Sorting a list
John Salerno
johnjsal at NOSPAMgmail.com
Thu Feb 1 14:35:05 EST 2007
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? Is there a better way to do this than making a list of tuples?
(So far I have a text file and on each line is a citation. I use an RE
to search for the year, then put this year and the entire citation in a
tuple, and add this tuple to a list. Perhaps this step can be changed to
be more efficient when I then need to sort them by date and write a new
file with the citations in order.)
Thanks.
More information about the Python-list
mailing list