Pre-PEP: Dictionary accumulator methods
Magnus Lie Hetland
mlh at selje.idi.ntnu.no
Sun Mar 20 10:55:59 EST 2005
In article <JbL_d.8237$qN3.2116 at trndny01>, 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
Yes, yes, YES!
*Man*, this would be useful.
> def appendlist(self, key, *values):
> try:
> self[key].extend(values)
> except KeyError:
> self[key] = list(values)
Woohoo! *Just* as useful.
I'd *definitely* use these.
Hot 100% sure about the names, though. (add() and append() seem like
more natural names -- but they may be confusing, considering their
other uses...)
+1 on both (possibly allowing for some naming discussion...)
--
Magnus Lie Hetland Time flies like the wind. Fruit flies
http://hetland.org like bananas. -- Groucho Marx
More information about the Python-list
mailing list