John Salerno a écrit : > Bruno Desthuilliers wrote: > >> John Salerno a écrit : >> >>> Hi everyone. If I have a list of tuples, and each tuple is in the form: >>> >>> (year, text) as in ('1995', 'This is a citation.') >>> >>> How can I sort the list so that they are in chronological order based >>> on the year? >> >> >> Calling sort() on the list should just work. > > > Amazing, it was that easy. :)
A very common Python idiom is "decorate/sort/undecorate", which is just what you've done here. It's usually faster than passing a custom comparison callback function (cf a recent thread named "Sorting a List of Lists, where Paddy posted a link to a benchmark). -- http://mail.python.org/mailman/listinfo/python-list