Map#get needs a default value param?

Tab Atkins Jr. jackalmage at gmail.com
Tue Jun 12 09:02:39 PDT 2012


On Tue, Jun 12, 2012 at 7:36 AM, David Bruant <bruant.d at gmail.com> wrote:
> Le 12/06/2012 16:19, Hemanth H.M a écrit :
>
> Would it be useful to have something like sum[value] = sum.get(value, 0) + 1
>
> You can always do
>
>     sum[value] = (sum.get(value) || 0) + 1;
>
> I think it's simple enough to justify not having an additional (and
> potentially confusing) argument, but I'm open to debate.

The default argument in python's Dict.get doesn't seem confusing, and
I've used it plenty.  (I've also used the more specialized Dict
variants that obviate it - Counter and DefaultDict.)

~TJ


More information about the es-discuss mailing list