Sorting Lists

Dudley Carr dcarr1 at hotmail.com
Wed Jul 25 18:55:50 EDT 2001


"Colin Meeks" <colin at meeks.ca> wrote in message news:<lSh77.64029$2V.13507417 at news3.rdc1.on.home.com>...
> I have a list that comprises of First Name, Surname, Age
> The list looks something like
> 
> [["Mickey","Mouse","50"],["Stan","Mantz","3"],["Junior","Wilst","40"],["Kim"
> ,"Bean","15"]]
> 
> How can I sort the list to rearrange it by either First Name, Surname, Age
> 

data = [["Mickey","Mouse","50"], ["Stan","Mantz","3"],
["Junior","Wilst","40"], ["Kim","Bean","15"]]
data.sort(lambda elem1, elem2: cmp(elem1[2], elem[2]))

That ought to sort the list on the age.

Dudley



More information about the Python-list mailing list