Pre-PEP: Dictionary accumulator methods
vze4rx4y at verizon.net
Sat Mar 19 08:54:58 CET 2005
> > d.count(key, qty)
> > d.appendlist(key, *values)
> How about an efficient duck-typing value-incrementer to replace both?
There is some Zen of Python that argues against this interesting idea. Also, I'm
concerned that by folding appendlist() into valadd() we would lose an important
cue that a list is being built-up.
Another issue is that duck-typed multiple-dispatch is only readable when the
type of the input argument is obvious from the surrounding code. Given
d.valadd(x), it is hard to grok if x was created by some code far away. Since a
primary goal is readability and clarity, having two separate, concrete methods
is likely better than having a single more-abstracted multi-purpose method. The
performance gains are just icing on the cake.
> I'm thinking the idea that the counting is happening with the value
> to the key should be emphasised more. Hence valadd or such?
How about countkey() or tabulate()?
More information about the Python-list