Sort

Remco Gerlich scarblac at pino.selwerd.nl
Wed Dec 6 14:55:14 CET 2000


Alfred <scj at mcom.mcom.fr> wrote in comp.lang.python:
> Hello world,
> 
> I'm trying to sort a List of List, on the third col, but I don't find how to
> do this.

# 'L' is a list of lists with at least three elements.
# No error checking is done.

def cmp_lists(A, B):
   # Function that compares two lists by their third element
   return cmp(A[2], B[2])
   
sortedlist = L[:]          # Make a copy, may be unnecessary
sortedlist.sort(cmp_lists) # Sort it using the function cmp_lists



More information about the Python-list mailing list