Maikisia (Ordered Set)

class mochila.OrderedSet(iterable=None)

An OrderedSet is an enumerated collection of items. The order in which the items appear in the collection matters and the same item can appear only once in the collection. Items in the collection must be hashable.

An OrderedSet behaves as the Python built-in set type. The main difference is that the non-operator versions of the update(), intersection_update(), difference_update(), and symmetric_difference_update() are not supported.

Additionally, as for Sequences, item access by index additionally supports an iterable as the index. In this case the result will be a Sequence of the items corresponding to those indices.

>>> m = OrderedSet('madagascar')
>>> print(m)
['m', 'a', 'd', 'g', 's', 'c', 'r']
>>> print(m[[0,2,5]])
['m', 'd', 'c']

OrderedSets can be constructed using the type constructor OrderedSet() or OrderedSet(iterable). The constructor builds an OrderedSet whose items are taken from iterable. To represent sets of sets, the inner sets must be frozenset objects. If iterable is not specified, a new empty OrderedSet is returned.

Parameters:iterable – An iterable from which items are taken to build the OrderedSet.