Sorting list (maybe stupid)
Charl P. Botha
cpbotha at i_triple_e.org
Tue Jun 11 05:43:21 EDT 2002
In article <slrnagbh7m.h03.jarvin24 at lehtori.cc.tut.fi>, Järvinen Petri wrote:
> I have a problem and can't solve it:
>
> There is lines of text like:
>
> 2. Header2
> 1. Header1
> 102. Header102
>
> and so on...
>
> And I need to sort them according to the number (1,2,3,4...)
Put each line in a tuple, first element the number, second element the
header. Make a list of these tuples, and then use list.sort() with a comp
function that compares using the first element in the tuple.
Here's some help:
>>> print [].sort.__doc__
L.sort([cmpfunc]) -- sort *IN PLACE*; if given, cmpfunc(x, y) -> -1, 0, 1
--
charl p. botha http://cpbotha.net/ http://visualisation.tudelft.nl/
More information about the Python-list
mailing list