[Tutor] pls. help me in sorting and choosing

Kent Johnson kent37 at tds.net
Thu Aug 11 13:45:32 CEST 2005

jfouhy at paradise.net.nz wrote:
> If you can do this, then it is easy to ask python to sort it for you.
>>>>data = [("NM_004619.2", 4910.8), ("NM_004619.2", 2716.3), ("NM_145759.1",
> 4805.7), ("NM_14 5759.1", 2716.3), ("XM_378692.1", 56.00)]
>>>>data.sort(key=lambda x: x[1], reverse=True)

You don't need a lambda here, you can use itertools.itemgetter(1). itemgetter() was added to Python 2.4 for this purpose.


More information about the Tutor mailing list