On Apr 15, 2005, at 03:32, [EMAIL PROTECTED] wrote:

Interestingly, the key argument is the solution to this problem:

arr = zip(range(10), range(10,0,-1))
arr
[(0, 10), (1, 9), (2, 8), (3, 7), (4, 6), (5, 5), (6, 4), (7, 3), (8, 2), (9, 1)]
arr.sort(key=lambda x: x[1])
arr
[(9, 1), (8, 2), (7, 3), (6, 4), (5, 5), (4, 6), (3, 7), (2, 8), (1, 9), (0, 10)]

Basically, key takes a function which, given a list element, returns the value
you actually want to sort by.

This absolutely rocks!
Okay, I hope the default version of Python in Mac OS 10.4 will be 2.4... Or else I'll have to move my lazy arse and install it by hand. Meh.


-- Max
maxnoel_fr at yahoo dot fr -- ICQ #85274019
"Look at you hacker... A pathetic creature of meat and bone, panting and sweating as you run through my corridors... How can you challenge a perfect, immortal machine?"



_______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Reply via email to