Pre-PEP: Dictionary accumulator methods

Matteo Dell'Amico della at toglimi.linux.it
Sun Mar 20 04:55:29 EST 2005


Raymond Hettinger wrote:
> I would like to get everyone's thoughts on two new dictionary methods:
> 
>         def count(self, value, qty=1):
>             try:
>                 self[key] += qty
>             except KeyError:
>                 self[key] = qty
> 
>         def appendlist(self, key, *values):
>             try:
>                 self[key].extend(values)
>             except KeyError:
>                 self[key] = list(values)

They look as a special-case to me. They don't solve the problem for 
lists of sets or lists of deques for instance, not to mention other 
possible user-defined containers.

defaultdicts look to me as a solution that is more elegant and solves 
more problems. What is the problem with them?

-- 
Ciao,
Matteo



More information about the Python-list mailing list