[Python-ideas] Add OrderedSet now that OrderedDict is in collections

Mart Sõmermaa mrts.pydev at gmail.com
Sun Apr 12 00:22:30 CEST 2009

There was a somewhat ancient discussion on OrderedDict and OrderedSet
before: http://mail.python.org/pipermail/python-dev/2005-March/051915.html

The resolution seemed to be that neither of them should be in stdlib. Now
that OrderedDict is in and Raymond Hettinger has created a solid OrderedSet
implementation: http://code.activestate.com/recipes/576694/ , could the
latter also be included in collections?

Here's a very generic use-case:

def _update_key(dct, key, val):
    Update a key in dict *dct*. If they key already exists in *dct* but the
    value doesn't, a set of previous values is created and the value added
to it.
    if key in dct:
        if dct[key] == val:
        s = set(dct[key])
        dct[key] = s
        dct[key] = val

The problem is that I both need to remove duplicates and retain insertion
order like list.append().
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20090412/708554fd/attachment.html>

More information about the Python-ideas mailing list