Fun with reverse sorts

bearophileHUGS at lycos.com bearophileHUGS at lycos.com
Fri Oct 3 06:22:28 EDT 2008


Chris Rebert:
> So the improved code is:
> your_list.sort(key=lambda elem: (elem[3], elem[2]), reverse=True)

Better (untested):
from operator import itemgetter
...
your_list.sort(key=itemgetter(3, 2), reverse=True)

Bye,
bearophile



More information about the Python-list mailing list