sorting a list of lists

Stefan Behnel stefan.behnel-n05pAM at web.de
Mon Aug 27 14:29:59 EDT 2007


iapain wrote:
>> i would like to sort a list of lists. The list is first sorted on the
>> second item in the sub-lists (which I can do), then on the third item
>> (which I can't).
> 
> Write a comparator instead of dirty hacks
> 
> mylistoflist.sort(mycomparator)
> 
> def mycomparator(a, b):
>   #do

Taking advantage of stable sorting is totally not a hack. The OP just tried
the two sorting steps in the wrong order.

Stefan



More information about the Python-list mailing list