Pre-PEP: Dictionary accumulator methods

Ivan Van Laningham ivanlan at pauahtun.org
Sat Mar 19 10:31:57 EST 2005


Hi All--

Raymond Hettinger wrote:
> 
> 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)
> 

I still prefer tally(), despite perceived political connotations. 
They're only connotations, after all, and tally() comprises both
positive and negative incrementing, whereas add() and addup() will tease
users into thinking they are only for incrementing.

What about adding another method, "setincrement()"?

d={}
d.setincrement(-1)
for word in text.split():
    d.tally(word,1)
    if word.lower() in ["a","an","the"]:
	d.tally(word)

Not that there's any real utility in that.

Metta,
Ivan
----------------------------------------------
Ivan Van Laningham
God N Locomotive Works
http://www.pauahtun.org/
http://www.andi-holmes.com/
Army Signal Corps:  Cu Chi, Class of '70
Author:  Teach Yourself Python in 24 Hours



More information about the Python-list mailing list