alwayssortedlist (was Re: On PEP 322 (ireverse))
Alex Martelli
aleax at aleax.it
Thu Oct 30 06:04:43 EST 2003
Bengt Richter wrote:
...
>>Perfectly right. If you DO want a listoid container that keeps its
>>elements sorted, that's not hard to make for yourself. There are
...
> No comments on the heapq module?
It can often offer a good _alternative_ to "a listoid container that keeps
its elements sorted" -- keeping them as a heap is cheaper than keeping them
sorted. But "if you DO want" them sorted, so that at any time accessing
mycontainer[x] gives me the x-th smallest item in mycontainer, heapq isn't
gonna be very effective.
There are many good alternatives to "keeping the elements sorted", and
heapq may well help implement some of them, but I wasn't discussing the
alternatives -- just the implementation strategies under the assumption
that the specs DO call for "always sorted".
Alex
More information about the Python-list
mailing list