Orderly Set

5.5.0 · active · verified Sat Mar 28

Orderly Set is a Python package providing several implementations of ordered set data structures, including `OrderlySet`, `StableSet`, `StableSetEq`, `OrderedSet`, and `RoughMaxSizeSet`. These implementations combine the uniqueness of a set with the order-preserving characteristics of a list or sequence, offering various performance trade-offs for operations such as insertion, deletion, membership testing, and index lookups. The library is actively maintained, with its current version being 5.5.0, and receives regular updates as evidenced by its GitHub release history.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates the creation and basic operations of `OrderedSet` and `StableSet`. `OrderedSet` acts like a hybrid of a list and a set, preserving insertion order with efficient index lookup but O(N) deletion. `StableSet` provides fast O(1) insertion, deletion, and membership testing, but O(N) index lookup.

from orderly_set import OrderedSet, StableSet

# Using OrderedSet
letters = OrderedSet('abracadabra')
print(f"OrderedSet: {letters}")  # Expected: OrderedSet(['a', 'b', 'r', 'c', 'd'])
print(f"'r' in letters: {'r' in letters}")
print(f"Index of 'r': {letters.index('r')}")
print(f"Item at index 2: {letters[2]}")
letters.add('x')
print(f"After adding 'x': {letters}")

# Using StableSet (different performance characteristics)
stable_items = StableSet([1, 5, 2, 5, 3])
print(f"StableSet: {stable_items}") # Expected: StableSet({1, 5, 2, 3})
stable_items.add(4)
print(f"After adding 4: {stable_items}")

view raw JSON →