Skip to main content

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__

Tested on Python 2.6, 2.7, 3.3, 3.4, PyPy, and PyPy3.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for ordered-set, version 1.3.1
Filename, size File type Python version Upload date Hashes
Filename, size ordered-set-1.3.1.tar.gz (2.9 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page