Pre-PEP: Dictionary accumulator methods
sjmachin at lexicon.net
Sat Mar 19 22:07:04 CET 2005
Raymond Hettinger wrote:
> I would like to get everyone's thoughts on two new dictionary
+1 for each.
> PROBLEMS BEING SOLVED
> The readability issues with the existing constructs are:
> * They are awkward to teach, create, read, and review.
> * Their wording tends to hide the real meaning (accumulation).
> * The meaning of setdefault() 's method name is not self-evident.
+1 to EACH of the above 3 points.
A question directed to the folk who had to look up "tally" in the
dictionary: Which dictionary includes "setdefault", "updateBy", etc?
> The performance issues with the existing constructs are:
> the performance improvement matches the readability
> The proposed names could possibly be improved (perhaps tally() is
> and clear than count()).
+3 for tally !!!
appendtolist is better than appendlist
> The appendlist() method is not as versatile as setdefault() which can
> with other object types (perhaps for creating dictionaries of
> However, most uses I've seen are with lists.
My use cases for tally:
(1) Yes the text-book "word" frequency gig applied in production
data-matching etc applications
(2) quick stats like from SQL "group by" e.g.
customer_value.tally(state, dollar_value) # real or *DECIMAL*
Use cases for appendlist: many; in general, how else do you implement a
one-to-many relationship in memory??
More information about the Python-list