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

Kevin Lee cockneykevin at gmail.com
Sun Mar 29 04:01:30 EDT 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 qq.com>

>
> 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.:)
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20090329/2217b989/attachment-0001.html>


More information about the Python-list mailing list