how to use "heapq" module as a max-heap?
paddy3118 at googlemail.com
Sun Mar 29 15:49:22 CEST 2009
On Mar 29, 8:36 am, "Apollo" <tju... at qq.com> wrote:
> as we all known, in the standard module 'heapq', we can easily get the smallest item from the heap. i.e. it's an implementation of min-heap.
> my question is how to use 'heapq' to extract the biggest item from the heap? is it possible?
> thanks in advance.:)
If heapifying something that will be compared by number, then use the
negative of the number in the object to be heapified. You can then
negate it when popped.
More information about the Python-list