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

Marcus Stojek stojek at
Mon Feb 18 11:26:35 CET 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