[Tutor] high score lists
Max Noel
maxnoel_fr at yahoo.fr
Fri Apr 15 17:26:18 CEST 2005
On Apr 15, 2005, at 03:32, jfouhy at paradise.net.nz 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?"
More information about the Tutor
mailing list