Pre-PEP: Dictionary accumulator methods

Michael Spencer mahs at telcopartners.com
Sat Mar 19 01:43:47 EST 2005


Raymond Hettinger wrote:
> I would like to get everyone's thoughts on two new dictionary methods:

+1 count
? appendlist

> 
> The proposed names could possibly be improved (perhaps tally() is more active
> and clear than count()).

IMO 'tally' is exactly the right method name

One issue is with negative increments reaching zero i.e., deleting the key once 
the tally goes to 0: this behavior would match the automatic key creation.

> The appendlist() method is not as versatile as setdefault() which can be used

Simpler list initialization augmentation would be very handy - but I would also 
like the equivalent functionality sets (don't care about dicts of dicts though).

Given the difference in set/list augmentation methods, this may present a 
challenge.  Alternatively, perhaps dict_of_list and dict_of_set could become 
specialized containers - they might then have value_append/value_extend and 
value_add methods respectively.  I imagine (without any basis in fact) that it 
would also be possible the optimize the performance of large mappings of 
containers compared with the generic dict.


Michael




More information about the Python-list mailing list