Skip to main content

OrderedSet

A set which keeps the ordering of the inserted items.

Attributes

AttributeTypeDescription
dictdictAn internal dictionary used to store elements as keys to maintain insertion order and ensure uniqueness.

Constructor

Signature

def OrderedSet(
iterable: iterable = None
) - > null

Parameters

NameTypeDescription
iterableiterable = NoneAn optional collection of items to initialize the set with.

Methods


add()

@classmethod
def add(
item: Any
) - > null

Adds a new item to the set or updates its position if it already exists, maintaining the insertion order.

Parameters

NameTypeDescription
itemAnyThe hashable element to be added to the collection

Returns

TypeDescription
nullNone

remove()

@classmethod
def remove(
item: Any
) - > null

Removes a specific item from the set; raises a KeyError if the item is not found.

Parameters

NameTypeDescription
itemAnyThe element to be removed from the collection

Returns

TypeDescription
nullNone

discard()

@classmethod
def discard(
item: Any
) - > null

Removes an item from the set if it is present, but does nothing if the item does not exist.

Parameters

NameTypeDescription
itemAnyThe element to be removed from the collection if it exists

Returns

TypeDescription
nullNone