dictionary initialization
Alex Martelli
aleaxit at yahoo.com
Sat Nov 27 02:18:39 EST 2004
Jeff Shannon <jeff at ccvcorp.com> wrote:
> Also, it's not that hard to subclass dict to provide the functionality
> that you want. I expect that googling on the c.l.p archives would turn
> up more than one recipe for a dict with default values. (There may even
> be such a thing in the Python Cookbook.) I know I've seen such things
> posted here (though not recently)
There are several such recipes. The most promising IMHO is Hettinger's
'bag' class (doesn't subclass dict -- uses containment and delegation --
but it deals best with maintaining count-per-item, aka multiset or bag);
it has several bugs as posted, but I've just finished editing it for the
2n edition and it wasn't hard to clear up. I do hope we'll have a
collections.bag in Python 2.5 one day.
Alex
More information about the Python-list
mailing list