Dead simple & fast ordered set using python's 3.7+ dict.
Project description
A dead simple set that preserves insertion order, internally using the python’s 3.7 dict, which preserves order.
pip install ordered-set-37
This class subclasses and implements all the methods of MutableSet.
x = OrderedSet([1, 2, -1, "bar"])
x.add(0)
assert list(x) == [1, 2, -1, "bar", 0]
This library uses the typing system, so feel free to do:
x: OrderedSet[str] = OrderedSet(("foo", "bar"))
x.add(1) # type checkers won't like this as it is not a string
As an extra, you can access a value by index (although the speed is at worst O(n)):
x = OrderedSet(["foo", "bar", "baz"])
assert x[1] == "bar"
For obvious reasons, this library is only Python 3.7+ compatible.
Feel free to contribute, fork, etc.
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 Distribution
Ordered-set-37-1.0b2.tar.gz
(2.7 kB
view details)
File details
Details for the file Ordered-set-37-1.0b2.tar.gz
.
File metadata
- Download URL: Ordered-set-37-1.0b2.tar.gz
- Upload date:
- Size: 2.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: Python-urllib/3.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f539e6e4a9478f7329a40fa7a372b4de37513c6ae105257c579b9663b60c5898 |
|
MD5 | 8c677b537be438223a9c003a3636c2ec |
|
BLAKE2b-256 | 98cddce6ca1f4d8067c93dea9e2f464672e188f41cb034a22d52aefc0e6bb648 |