[Tutor] Newbie: Sorting lists of lists

Keith Troell ktroell at mac.com
Thu Jun 19 02:30:05 CEST 2008


Let's say I have a list of lists l == [[1, 2, 3], [2, 3, 1], [3, 2,  
1], [1, 3, 2]]

If I do a l.sort(), it sorts on the first element of each listed list:

 >>> l.sort()
 >>> l
[[1, 2, 3], [1, 3, 2], [2, 3, 1], [3, 2, 1]]


How can I sort on the second or third elements of the listed lists?

Keith

A++ G++ PKR+ !PEG- B++ TB ADB- M+++ CHOW++
http://zbigniew.pyrzqxgl.com/bargegeek.html




More information about the Tutor mailing list