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
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 -
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
"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
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
*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