Sorted and reversed on huge dict ?

Fredrik Lundh fredrik at pythonware.com
Fri Nov 3 14:51:13 EST 2006


Paul Rubin wrote:

>>      items = d.items()
>>      items.sort(key=operator.itemgetter(1), reverse=True)
>>
>> the items list would require a couple of megabytes for 150k dictionary
>> entries, or so.  the key map needs some memory too, but the rest of
>> the sort is done in place.
> 
> I think the OP's method avoided the key map.

right. I should have written "most efficient", not memory efficient. 
the items+itemgetter approach is a bit faster, but uses a few extra 
megabytes of memory temporarily, during the sort.

</F>




More information about the Python-list mailing list