An implementation of mutable and immutable ordered sets.
Project description
orderedsets
An implementation of mutable and immutable ordered sets as thin wrappers around
Python's dict class.
These classes are meant as drop-in replacements for Python's builtin set and
frozenset classes. Care has been taken to provide the same functionality as the Python classes,
without API additions or removals, to allow easy switching between set implementations. These classes are often
faster than other ordered set implementations
(but slower than Python's builtin sets).
In contrast to Python's builtin set and frozenset classes, the order of
items is kept (generally, insertion order), such that iterating over items in
the set as well as mutating operations are deterministic.
This package has no external dependencies.
Usage
Install this package with:
$ pip install orderedsets
Usage example:
from orderedsets import OrderedSet, FrozenOrderedSet
os = OrderedSet([1, 2, 4])
os.add(0)
assert list(os) == [1, 2, 4, 0]
os.remove(0)
fos = FrozenOrderedSet([1, 2, 4])
# a.add(0) # raises AttributeError: 'FrozenOrderedSet' object has no attribute 'add'
assert list(fos) == [1, 2, 4]
# sets with the same elements compare equal
assert os == fos == set([1, 2, 4]) == frozenset([1, 2, 4])
# only immutable sets can be hashed
assert hash(fos) == hash(frozenset([1, 2, 4]))
Please also see the documentation.
References
Other packages
- https://github.com/rindPHI/proxyorderedset/ (not 100% compatible with set)
- https://pypi.tw.martin98.com/project/ordered-set/ (no frozen/immutable class)
- https://pypi.tw.martin98.com/project/stableset/ (no frozen/immutable class)
- https://pypi.tw.martin98.com/project/orderedset/ (Cython, no frozen/immutable class)
- https://pypi.tw.martin98.com/project/Ordered-set-37/ (no frozen/immutable class)
- https://pypi.tw.martin98.com/project/sortedcollections (no frozen/immutable class)
- https://github.com/grantjenks/python-sortedcollections (no frozen/immutable class)
- https://github.com/Erotemic/ubelt (pure Python, no frozen/immutable class)
Discussions
Python implementations
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file orderedsets-2025.2-py3-none-any.whl.
File metadata
- Download URL: orderedsets-2025.2-py3-none-any.whl
- Upload date:
- Size: 7.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9e59a09d338e7e8aeaafe5b214fffceb74886cb6bb8586ae7b68bc7395e01f70
|
|
| MD5 |
77e993bc8746ad44e1367c28db286303
|
|
| BLAKE2b-256 |
890d920698bd9231e13882fb6144962855a850202f2df6317fded454c0c95a45
|