Pre-PEP: Dictionary accumulator methods
vze4rx4y at verizon.net
Sat Mar 19 09:10:58 CET 2005
> Dunno, to me "tally" reads "counts the numbers of votes for a candidate
> in an election".
That isn't a pleasant image ;-)
> only right name would be "get_and_possibly_set" but it is a bit long to
>> Even if a wording is found that better describes the both the get and
>> set operation, it is still a distractor from the intent of the combined
>> statement, the intent of building up a list. That is an intrinsic wording
>> limitation that cannot be solved by a better name for setdefault.
>> If any change is made at all, we ought to go the distance and provide a
>> better designed tool rather than just a name change.
> Well, I never figured out that the intent of setdefault was to build up
> a list ;)
Right! What does have that intent is the full statement: d.setdefault(k,
My thought is that setdefault() is rarely used by itself. Instead, it is
typically part of a longer sentence whose intent and meaning is to accumulate or
build-up. That meaning is not well expressed by the current idiom.
More information about the Python-list