reversed heapification?

Kent Johnson kent37 at tds.net
Mon Mar 7 09:00:06 EST 2005


Stefan Behnel wrote:
> 
> Kent Johnson wrote:
> 
>> heapq.nlargest()
>> heapq.nsmallest()
> 
> 
> On second thought, that doesn't actually get me very far. I do not know 
> in advance how many I must select since I need to remove duplicates 
> *after* sorting (they are not necessarily 'duplicate' enough to fall 
> into the same sort bucket). What I'd like to do is heapify and then 
> create an iterator for the result. But since heapify doesn't support 
> "reverse" ...
> 
> Any other ideas?

Wrap your data in a class that defines __cmp__ as the inverse of __cmp__ on the underlying data, 
then use heapq?
Just sort the list?

Kent

> 
> Stefan



More information about the Python-list mailing list