Ordered Set Recipe

class sortedcollections.OrderedSet(iterable=())[source]

Like OrderedDict, OrderedSet maintains the insertion order of elements.

For example:

>>> ordered_set = OrderedSet('abcde')
>>> list(ordered_set) == list('abcde')
True
>>> ordered_set = OrderedSet('edcba')
>>> list(ordered_set) == list('edcba')
True

OrderedSet also implements the collections.Sequence interface.

__contains__(key)[source]

key in ordered_set

__getitem__(index)[source]

ordered_set[index] -> element; lookup element at index.

__init__(iterable=())[source]

Initialize self. See help(type(self)) for accurate signature.

__iter__()[source]

iter(ordered_set)

__len__()[source]

len(ordered_set)

__repr__()[source]

Text representation of set.

__reversed__()[source]

reversed(ordered_set)

__str__()

Text representation of set.

__weakref__

list of weak references to the object (if defined)

add(value)[source]

Add element, value, to set.

count(key)

key in ordered_set

discard(value)[source]

Remove element, value, from set if it is a member.

index(value)[source]

Return index of value.