reversed heapification?

Kent Johnson kent37 at tds.net
Mon Mar 7 07:39:54 EST 2005


Stefan Behnel wrote:
> 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.

heapq.nlargest()
heapq.nsmallest()
?

Python 2.4 only

Kent



More information about the Python-list mailing list