colour.utilities.OrderedSet#

class colour.utilities.OrderedSet(iterable: Iterable[T] | None = None)[source]#

Bases: MutableSet[T]

Represent a set-like object preserving the insertion order of its elements.

Parameters:

iterable (Iterable[T] | None) – Elements to initialise the ordered set with.

Methods

Notes

  • The elements are stored as the keys of a dict, which preserves the insertion order and retains the constant-time membership test of a set.

Examples

>>> ordered_set = OrderedSet(["c", "a", "b"])
>>> ordered_set
OrderedSet(['c', 'a', 'b'])
>>> ordered_set.add("a")
>>> list(ordered_set)
['c', 'a', 'b']
>>> ordered_set.discard("c")
>>> list(ordered_set)
['a', 'b']
__init__(iterable: Iterable[T] | None = None) None[source]#
Parameters:

iterable (Iterable[T] | None)

Return type:

None

__contains__(element: object) bool[source]#

Return whether the ordered set contains the specified element.

Parameters:

element (object) – Element to check the presence of.

Returns:

Whether the ordered set contains the element.

Return type:

bool

__iter__() Generator[T, None, None][source]#

Return a generator over the ordered set elements, in insertion order.

Yields:

Generator – Ordered set elements.

Return type:

Generator[T, None, None]

__len__() int[source]#

Return the ordered set element count.

Returns:

Ordered set element count.

Return type:

int

__repr__() str[source]#

Return an evaluable string representation of the ordered set.

Returns:

Evaluable string representation.

Return type:

str

__reversed__() Generator[T, None, None][source]#

Return a generator over the ordered set elements, in reversed insertion order.

Yields:

Generator – Ordered set elements.

Return type:

Generator[T, None, None]

add(value: T) None[source]#

Add the specified element to the ordered set, keeping the position of an element already present.

Parameters:

value (T) – Element to add.

Return type:

None

discard(value: T) None[source]#

Remove the specified element from the ordered set if present.

Parameters:

value (T) – Element to remove.

Return type:

None

__weakref__#

list of weak references to the object

copy() OrderedSet[T][source]#

Return a shallow copy of the ordered set.

Returns:

Shallow copy of the ordered set.

Return type:

colour.utilities.OrderedSet

Examples

>>> ordered_set = OrderedSet(["c", "a", "b"])
>>> ordered_set.copy()
OrderedSet(['c', 'a', 'b'])