Skip to content

Dead simple & fast ordered set using python's 3.7+ dict.

License

Notifications You must be signed in to change notification settings

bustawin/ordered-set-37

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Ordered Set

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.

About

Dead simple & fast ordered set using python's 3.7+ dict.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages