finesse.utilities.collections module

class finesse.utilities.collections.OrderedSet(iterable=None)[source]

Bases: object

An ordered set implementation using an Dictionary to maintain the order of elements. Dictionaries in recent Python versions are all ordered now.

Parameters

iterableiterable, optional

An optional iterable to initialize the ordered set with elements.

Attributes

_dictDict

The internal dictionary used to maintain order and uniqueness of elements.

Methods

add(item)

Add an element to the OrderedSet.

remove(item)

Remove an element from the OrderedSet.

difference_update(iterable)

Remove all elements from the OrderedSet that are also in the provided iterable.

update(iterable)

Add all elements from the provided iterable to the OrderedSet.

clear()

Remove all elements from the OrderedSet.

__contains__(item)

Check if an element is in the OrderedSet.

__iter__()

Return an iterator over the elements of the OrderedSet.

__len__()

Return the number of elements in the OrderedSet.

__repr__()

Return a string representation of the OrderedSet.

add(self, item)[source]

Add an element to the OrderedSet.

Parameters

itemobject

The element to be added to the OrderedSet.

clear(self)[source]

Remove all elements from the OrderedSet.

copy(self)[source]

Create a shallow copy of this OrderedSet.

Returns

OrderedSet

A new OrderedSet with the same elements as the current set.

difference(self, other)[source]

Return a new OrderedSet with elements that are the difference between the two.

Parameters

otherOrderedSet

Another OrderedSet to subtract from this set.

Returns

OrderedSet

A new OrderedSet with the difference between the sets.

difference_update(self, iterable)[source]

Remove all elements from the OrderedSet that are also in the provided iterable.

Parameters

iterableiterable

An iterable containing elements to be removed from the OrderedSet.

issubset(self, other)[source]

Check if this set is a subset of another set.

Parameters

otherOrderedSet

Another OrderedSet to check against.

Returns

bool

True if this set is a subset of other, False otherwise.

remove(self, item)[source]

Remove an element from the OrderedSet.

Parameters

itemobject

The element to be removed from the OrderedSet.

Raises

KeyError

If the element is not present in the OrderedSet.

union(self, *others)[source]

Return a new OrderedSet with elements from the union of this set and other.

Parameters

othersOrderedSet

Another OrderedSet to union with this set.

Returns

OrderedSet

A new OrderedSet with all unique elements from both sets.

update(self, iterable)[source]

Add all elements from the provided iterable to the OrderedSet.

Parameters

iterableiterable

An iterable containing elements to be added to the OrderedSet.