[Python-Dev] Proposal: defaultdict (original) (raw)

Ilya Sandler ilya at bluefir.net
Sat Feb 18 08:03:42 CET 2006


On Fri, 17 Feb 2006, Phillip J. Eby wrote:

> d = {} # or dict() > d.defaultfactory = list

Why not a classmethod constructor: d = dict.withfactory(list) But I'd rather set the default and create the dictionary in one operation, since when reading it as two, you first think 'd is a dictionary', and then 'oh, but it has a default factory', as opposed to "d is a dict with a factory" in one thought.

Also, class method would mean less typing (esp if dictionary name happens to be longer than a couple of characters ;-)

But I'd like to suggest a different name:

d = dict.with_default( list)

Ilya



More information about the Python-Dev mailing list