[Python-ideas] Identity dicts and sets (original) (raw)

Bruce Leban bruce at leapyear.org
Wed Jan 2 22:33:30 CET 2013


On Wed, Jan 2, 2013 at 1:13 PM, Masklinn <masklinn at masklinn.net> wrote:

Wouldn't it make more sense to provide e.g. collections.KeyedDictionary(key, seq, **kwargs)? It would be clear and would allow implementations to provide dedicated implementations for special cases (such as key=id) if desired or necessary. defaultdict already follows this pattern, so there's a precedent.

I agree collections is the place to put it but that would give us three specialized subclasses of dictionary which cannot be combined. That is, I can have a dictionary with a default, one that is ordered or one that uses a key function but not any combination of those. It would seem better to have something like Haoyi Li suggested:

collections.Dictionary(default=None, ordered=False, key=None) --> a dict subclass

of course collections.OrderedDictionary and collections.defaultdict would continue to be available as appropriate aliases to collections.Dictionary.

--- Bruce Check it out: http://kck.st/YeqGxQ -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-ideas/attachments/20130102/3ad8c2ed/attachment.html>



More information about the Python-ideas mailing list