Skip to main content

An implementation of mutable and immutable ordered sets.

Project description

PyPI version License PyPI - Downloads

orderedsets

An implementation of mutable and immutable ordered sets as thin wrappers around Python's dict class for the OrderedSet class, and immutabledict for the FrozenOrderedSet 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.

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 requires the immutabledict package for the immutable set class, but has no other 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]))

References

Other packages

Discussions

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

orderedsets-2023.1-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

Details for the file orderedsets-2023.1-py3-none-any.whl.

File metadata

File hashes

Hashes for orderedsets-2023.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6c7dacdd24554a92ce3860b0d5520af3dd3e4845216f83ba31ef989fee513349
MD5 3723fcc3a86a4ce494974faf6cd82245
BLAKE2b-256 18d3a5cd95433a27c2c2cef5eb19b7a9a55ef543c862baaeff26138c8258f545

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page