how to use "heapq" module as a max-heap?

Kevin Lee cockneykevin at
Sun Mar 29 10:01:30 CEST 2009

I suppose you could wrap your value type in a class and reimplement the
builtin __cmp__ method to make it behave reversely or if it's a builtin
numeric value type you could even push the negative into the heap in the
first place?
2009/3/29 Apollo <tjuhzj at>

> 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.:)
> --
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Python-list mailing list