Pre-PEP: Dictionary accumulator methods

Raymond Hettinger vze4rx4y at verizon.net
Sat Mar 19 10:17:59 EST 2005


[Dan Sommers]
> Curious that in this lengthy discussion, a method name of "accumulate"
> never came up.  I'm not sure how to separate the two cases (accumulating
> scalars vs. accumulating a list), though.

Separating the two cases is essential.  Also, the wording should contain strong
cues that remind you of addition and of building a list.

For the first, how about addup():

    d = {}
    for word in text.split():
         d.addup(word)


Raymond





More information about the Python-list mailing list