Re: [Tutor] which is better solution of the question

2009-06-16 Thread Lie Ryan
Abhishek Tiwari wrote: > *Question :* > The first list contains some items, and the second list contains their > value (higher is better). > > items = [apple, car, town, phone] > values = [5, 2, 7, 1] > > Show how to sort the 'items' list based on the 'values' list so that you > end up with the

Re: [Tutor] which is better solution of the question

2009-06-16 Thread Emile van Sebille
On 6/16/2009 7:49 AM Kent Johnson said... How do you measure "better"? Speed, clarity, ...? ... or the first method you think of that gives the right result. Where else would you find your keys once you've found them? Emile ___ Tutor maillist -

Re: [Tutor] which is better solution of the question

2009-06-16 Thread Kent Johnson
On Tue, Jun 16, 2009 at 9:52 AM, Abhishek Tiwari wrote: > Question : > The first list contains some items, and the second list contains their value > (higher is better). > > items = [apple, car, town, phone] > values = [5, 2, 7, 1] > > Show how to sort the 'items' list based on the 'values' list so

Re: [Tutor] which is better solution of the question

2009-06-16 Thread Alan Gauld
"Abhishek Tiwari" wrote *Ans. 1* values, items = list(zip(*sorted(zip(values,items), reverse=True))) Personally I find that just a bit too dense so I'd break it out to: s = sorted(zip(values,items), reverse=True) values = [v for v,i in s] items = [i for v,i in s] *Ans. 2* new_values = so

Re: [Tutor] which is better solution of the question

2009-06-16 Thread Wayne
On Tue, Jun 16, 2009 at 8:52 AM, Abhishek Tiwari wrote: > *Question :* > The first list contains some items, and the second list contains their > value (higher is better). > > items = [apple, car, town, phone] > values = [5, 2, 7, 1] > > Show how to sort the 'items' list based on the 'values' li

[Tutor] which is better solution of the question

2009-06-16 Thread Abhishek Tiwari
*Question :* The first list contains some items, and the second list contains their value (higher is better). items = [apple, car, town, phone] values = [5, 2, 7, 1] Show how to sort the 'items' list based on the 'values' list so that you end up with the following two lists: items = [town, appl