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.
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.0b1.tar.gz
(2.6 kB
view details)
File details
Details for the file Ordered-set-37-1.0b1.tar.gz
.
File metadata
- Download URL: Ordered-set-37-1.0b1.tar.gz
- Upload date:
- Size: 2.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: Python-urllib/3.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 89a9779c24a8a8bd6bceb9b9668b995412b59056be12e0a65eef70d6aabe1576 |
|
MD5 | 8f8f7d9e621b3fbb5c9f6bcf10087689 |
|
BLAKE2b-256 | a0faa81f6771ba19aee72002cf89d42abf898a1e895d69e0fee266d85514f26c |