Sorting a list

John Salerno johnjsal at NOSPAMgmail.com
Thu Feb 1 14:58:34 EST 2007


John Salerno wrote:
> 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. :)

One more thing. What if I want them in reverse chronological order? I 
tried reverse() but that seemed to put them in reverse alphabetical 
order based on the second element of the tuple (not the year).



More information about the Python-list mailing list