[Tutor] a better way to express this

Sean 'Shaleh' Perry shalehperry@attbi.com
Tue, 15 Jan 2002 17:34:43 -0800 (PST)


> Actually Danny's implementation is correct.  Yes you are right that the
> setdefault will set the value if it is not set, however in the code
> snippet the goal is to increment the value for the given key.  the
> implementation using setdefault would only work like this:
> 
>   dict.setdefault(key,0)
>   dict[key] = dict[key] + 1
> 
> Danny's
>   dict[key] = dict.get(key,0) + 1
> looks better to me
> 

I am also forced to use 1.5.x still.  But I agree, this looks and feels better
as well.  Went through and implemented it today, made things much happier.