Pre-PEP: Dictionary accumulator methods

Denis S. Otkidach ods at strana.ru
Sat Mar 19 10:24:35 EST 2005


On 18 Mar 2005 21:03:52 -0800 Michele Simionato wrote:

MS> +1 for inc instead of count.
MS> appendlist seems a bit too specific (I do not use dictionaries of
MS> lists that often).

inc is too specific too.

MS> The problem with setdefault is the name, not the functionality.

The problem with functionality: d.setdefault(k, v) can't be used as
lvalue.  If it could, we wouldn't need count/inc/add/tally method.

MS> get_or_set would be a better name: we could use it as an alias for
MS> setdefault and then remove setdefault in Python 3000.

What about d.get(k, setdefault=v) alternative?  Not sure whether it's
good idea to overload get() method, just an idea.

-- 
Denis S. Otkidach
http://www.python.ru/      [ru]



More information about the Python-list mailing list