orderedset package

OrderedSet

class orderedset.OrderedSet

An OrderedSet object is an ordered collection of distinct hashable objects.

It works like the set type, but remembers insertion order.

It also supports __getitem__() and index(), like the list type.

__getitem__(index)

Return the elem at index. Raises IndexError if index is out of range.

add(self, elem)

Add element elem to the set.

clear(self)

Remove all elements from the set.

copy(self)
Return type:OrderedSet
Returns:a new OrderedSet with a shallow copy of self.
difference(self, other)

OrderedSet - other

Return type:OrderedSet
Returns:a new OrderedSet with elements in the set that are not in the others.
difference_update(self, other)

OrderedSet -= other

Update the OrderedSet, removing elements found in others.

discard(self, elem)

Remove element elem from the OrderedSet if it is present.

index(self, elem)

Return the index of elem. Rases ValueError if not in the OrderedSet.

intersection(self, other)

OrderedSet & other

Return type:OrderedSet
Returns:a new OrderedSet with elements common to the set and all others.
intersection_update(self, other)

OrderedSet &= other

Update the OrderedSet, keeping only elements found in it and all others.

isdisjoint(self, other)

Return True if the set has no elements in common with other. Sets are disjoint if and only if their intersection is the empty set.

Return type:bool
isorderedsubset(self, other)
isorderedsuperset(self, other)
issubset(self, other)

OrderedSet <= other

Return type:bool

Test whether the OrderedSet is a proper subset of other, that is, OrderedSet <= other and OrderedSet != other.

issuperset(self, other)

OrderedSet >= other

Return type:bool

Test whether every element in other is in the set.

pop(self, last=True)

Remove last element. Raises KeyError if the OrderedSet is empty.

remove(self, elem)

Remove element elem from the set. Raises KeyError if elem is not contained in the set.

symmetric_difference(self, other)

OrderedSet ^ other

Return type:OrderedSet
Returns:a new OrderedSet with elements in either the set or other but not both.
symmetric_difference_update(self, other)

OrderedSet ^= other

Update the OrderedSet, keeping only elements found in either set, but not in both.

union(self, other)

OrderedSet | other

Return type:OrderedSet
Returns:a new OrderedSet with elements from the set and all others.
update(self, other)

OrderedSet |= other

Update the OrderedSet, adding elements from all others.