An OrderedSet is a custom MutableSet that remembers its order, so that every entry has an index that can be looked up.
Based on a recipe originally posted to ActiveState Recipes by Raymond Hettiger, and released under the MIT license:
Rob Speer’s changes are as follows:
changed the content from a doubly-linked list to a regular Python list. Seriously, who wants O(1) deletes but O(N) lookups by index?
add() returns the index of the added item
index() just returns the index of an item
added a __getstate__ and __setstate__ so it can be pickled
added __getitem__
__getitem__ and index() can be passed lists or arrays, looking up all the elements in them to perform NumPy-like “fancy indexing”
minghu6’s changes are as follow:
restrict the OrderedSet operation object: only themselves. Because OrderededSet’s element consists of its index and value, Python set’s element only consists of its value, however. I have written a new class OrderedSetAdapter to adapt Python set.
writtern a new class OrderedSetAdapter
rewrittern some contradictory method from collections.MutableSet
Tested on Python 2.7, 3.3, 3.4, 3.5, 3.6, PyPy, and PyPy3.
Release files for ordered-set-minghu6 3.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| ordered_set_minghu6-3.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Release files / ordered_set_minghu6-3.1.0-py3-none-any.whl
| Download URL | ordered_set_minghu6-3.1.0-py3-none-any.whl |
|---|---|
| Size | 5.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
535fd0d2676528e750beb12d5ac03bcaea14fb5204148a79794f0fdb978d47be
|
|
BLAKE2b-256 checksum How to use checksums |
00eae5c83329180e4ebef49d7f55c926f86b3cd4968b574b0108b97c1fb10b43
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.10.4
|