[Tutor] Sorting more than one list

Liam Clarke cyresse at gmail.com
Fri Apr 1 05:20:38 CEST 2005


What's b.index(x) do?

I'm guessing the for a list Delta = ["a,"b","c"], you get 

Delta.index("b")

1

Am I right? 

On Apr 1, 2005 1:16 PM, py <py at runsun.info> wrote:
> 
> 
> An alternative way of doing this (if you have python 2.4): 
> 
> >>> ppl =   ['john', 'mary', 'lary', 'jane']
> >>> age =   [15, 30, 23, 25]
> >>> height= [160, 165, 178, 170]
> 
> >>> sortby = lambda a, b: [a[b.index(x)] for x in sorted(b)]
> >>> sortby(ppl, age)
> ['john', 'lary', 'jane', 'mary']
> >>> sortby(ppl, height)
> ['john', 'mary', 'jane', 'lary'] 
> 
> >>> age    # age is not changed
> [15, 30, 23, 25] 
> 
>   
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
> 
> 
> 


-- 
'There is only one basic human right, and that is to do as you damn well please.
And with it comes the only basic human duty, to take the consequences.


More information about the Tutor mailing list