sorting list of tuples by second (third...) tuple item

Marcus Stojek stojek at part-gmbh.de
Mon Feb 18 05:26:35 EST 2002


>
>But this tends to be pretty slow.  For large lists, it's usually
>considered that the "decorate-sort-undecorate" pattern is the most
>effective way.  Something like this:
>
>def SortOnItem(mylist, index):
>    templist = [ (line[index], line) for line in mylist ]
>    templist.sort()
>    return [ line[1:] for line in templist ]
>
yapp. That's what I was looking for.
Thanks Marcus



More information about the Python-list mailing list