Sort

Steve Horne sh at ttsoftware.co.uk
Wed Dec 6 06:25:57 EST 2000


On Wed, 06 Dec 2000 09:07:57 GMT, "Alfred" <scj at mcom.mcom.fr> wrote:

>I'm trying to sort a List of List, on the third col, but I don't find how to
>do this.

You can specify an alternative comparison function to the sort method.
The easiest way to do this is with a lambda...

l.sort (lambda a, b : a[2] < b[2])

For comparison, the following should do the same as the basic sort
(but slower)...

l.sort (lambda a, b : a < b)

-- 
Steve Horne
Home : steve at lurking.demon.co.uk
Work : sh at ttsoftware.co.uk



More information about the Python-list mailing list