Pre-PEP: Dictionary accumulator methods

Duncan Booth duncan.booth at invalid.invalid
Sun Mar 20 10:52:44 CET 2005

Raymond Hettinger wrote:

> The rationale is to replace the awkward and slow existing idioms for
> dictionary based accumulation:
>     d[key] = d.get(key, 0) + qty
>     d.setdefault(key, []).extend(values)

How about the alternative approach of allowing the user to override the 
action to be taken when accessing a non-existent key?


and the accumulation becomes:

   d[key] += 1



would allow a safe:


More information about the Python-list mailing list