reversed heapification?

Stefan Behnel stefan.behnel-n05pAM at web.de
Mon Mar 7 13:16:43 CET 2005


Hi!

I need a general-purpose best-k sorting algorithm and I'd like to use heapq
for that (heapify + heappop*k). The problem is that heapify and heappop do not
support the "reverse" keyword as known from sorted() and list.sort(). While
the decorate-sort-undecorate pattern allows me to replace the "key" option, I
do not see an obvious way to have heapq work in a reverse way without making
assumptions on the data.

Any ideas?

Stefan



More information about the Python-list mailing list