OrderedSet
A set which keeps the ordering of the inserted items.
Attributes
| Attribute | Type | Description |
|---|---|---|
| dict | dict | An internal dictionary used to store elements as keys to maintain insertion order and ensure uniqueness. |
Constructor
Signature
def OrderedSet(
iterable: iterable = None
) - > null
Parameters
| Name | Type | Description |
|---|---|---|
| iterable | iterable = None | An 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
| Name | Type | Description |
|---|---|---|
| item | Any | The hashable element to be added to the collection |
Returns
| Type | Description |
|---|---|
null | None |
remove()
@classmethod
def remove(
item: Any
) - > null
Removes a specific item from the set; raises a KeyError if the item is not found.
Parameters
| Name | Type | Description |
|---|---|---|
| item | Any | The element to be removed from the collection |
Returns
| Type | Description |
|---|---|
null | None |
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
| Name | Type | Description |
|---|---|---|
| item | Any | The element to be removed from the collection if it exists |
Returns
| Type | Description |
|---|---|
null | None |