"Raymond Hettinger" <[EMAIL PROTECTED]> writes: > [Michele Simionato] > > +1 for inc instead of count. > > Any takers for tally()?
I'd say "tally" has some connotation of a counter that can never go negative. I don't know if that behavior is desirable. Someone suggested deleting the key if the tally is decremented to 0. I'd suggest instead throwing an exception on an attempt to decrement it to less than 0. > We should avoid abbreviations like inc() or incr() that different > people tend to abbreviate differently (for example, that is why the > new partial() function has its "keywords" argument spelled-out). Ok, "increment" then. > The only other issue I see with that name is that historically > incrementing is more associated with +=1 than with +=n. Also, there > are reasonable use cases for a negative n and it would be misleading > to call it incrementing when decrementing is what is intended. Setting the default to 1 is enough for that. I mean, adding a negative number to something is normally called "subtraction", but you can still pass a negative argument to __iadd__. > The issue with add() is that other types with that method use it for > a radically different purpose. For example, aSet.add(n) is not at > all similar in function to the proposed aDict.tally(n) Hmm, ok. > I'm curious. When you do use setdefault, what is the typical second > argument? In all the code I've encountered, nine times out of ten > it is []. Yeah, me too. -- http://mail.python.org/mailman/listinfo/python-list