orderedset: An ordered set

Inspiration and code expanded from Raymond Hettinger’s indexable weak ordered set and Stephan Schroevers’ does python have an ordered set stackoverflow.com postings.

class OrderedSet(values=())

Bases: MutableSet

Ordered set.

Supports all of the operations that can happen on a set.

add(self, value)

Experimental API . Add an element.


Experimental API . This is slow (creates N new iterators!) but effective.

discard(self, value)

Experimental API . Remove an element. Do not raise an exception if absent.

issubset(self, other)

Experimental API . Return self<=value.

issuperset(self, other)

Experimental API . Return self>=value.

class OrderedWeakrefSet(values=())

Bases: WeakSet

Ordered set of weak references