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.
from ordered_set_37 import OrderedSet
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-2.0.tar.gz
(3.6 kB
view hashes)
Built Distribution
Close
Hashes for Ordered_set_37-2.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 994cb95b9fc788fd8b5cc1741f98ced43c85b5b412a988745d16c66d1d77a9ad |
|
MD5 | ebff8d1cb49a302f3c2e71d2e13543a6 |
|
BLAKE2b-256 | 468ddf7f804b42c54c2e3cfc0e5408ea69fb06f8101dc03105f10d410e2cc69e |