A MutableSet that remembers its order, so that every entry has an index.
Project description
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”
Tested on Python 2.6, 2.7, 3.3, 3.4, 3.5, PyPy, and PyPy3.
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
File details
Details for the file ordered-set-2.0.1.tar.gz
.
File metadata
- Download URL: ordered-set-2.0.1.tar.gz
- Upload date:
- Size: 3.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 55567f094481ba204ffede0117ab563e19af050c7cbf33a9a23292b8cb2b0a0e |
|
MD5 | 3111c0dd1417b6421eb982e4cd4d0d68 |
|
BLAKE2b-256 | 808c7405f2f1a5b4a95fbc87b1e43df9a630aa30d93c0cfb06a9ea64fd436399 |