sorteddict 1.2.1
A dictionary that is sorted by key or by the given cmp or key function.
For Python 3 see the version that is provided in my book "Programming in Python 3"---it is in the book's downloadable examples available from my website.
- Provides a dictionary with the same methods and behavior as a
standard dict and that can be used as a drop-in replacement for a dict (apart from the constructor), but which always returns iterators and lists (whether of keys or values) in sorted order. It does not matter when items are inserted or when removed, the items in the sorteddict are always returned in sorted order. The ordering is implicitly based on the key's __lt__() (or failing that __cmp__()) method if no cmp or key function is given.
The main benefit of sorteddicts is that you never have to explicitly sort.
This particular implementation has reasonable performance if the pattern of use is: lots of edits, lots of lookups, ..., but gives its worst performance if the pattern of use is: edit, lookup, edit, lookup, ..., in which case using a plain dict and sorted() will probably be better.
| File | Type | Py Version | Uploaded on | Size | # downloads |
|---|---|---|---|---|---|
| sorteddict-1.2.1.tar.gz (md5) | Source | 2007-09-27 | 5KB | 757 | |
| sorteddict-1.2.1.zip (md5) | Source | 2007-09-27 | 6KB | 870 | |
- Author: Mark Summerfield
- Home Page: http://www.qtrac.eu
- Download URL: http://www.qtrac.eu/sorteddict.py
- Keywords: sorted,ordered,dict,data structure
- License: GPL v 3
- Platform: Any
- Categories
- Package Index Owner: MarkSummerfield
- DOAP record: sorteddict-1.2.1.xml
