how to sort a hash list without generating a new object?
stutzbach at google.com
Wed Aug 3 18:33:17 CEST 2011
On Tue, Aug 2, 2011 at 5:53 PM, Chris Rebert <clp2 at rebertia.com> wrote:
> If you /really/ need a sorted mapping datatype, google for
> "sorteddict" (which is quite distinct from OrderedDict).
> Or look for a binary search tree or skip list implementation of some
> sort; but these aren't commonly used in Python, so it may be hard to
> find a good one.
The blist package (I'm the author) provides a list-like type that has O(log
n) insertions and deletions. It provides a sorteddict type that uses the
blist type under-the-hood.
blist's "sorteddict" supports the "key" parameter (which works like
list.sort's key parameter), which the original poster could use to maintain
the keys in reverse order.
There's no overhead to learn how to use the new types. A blist works
exactly like a list but with different performance characteristics, and a
sorteddict works just like a dict but keeps the keys sorted.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-list