sorting two corresponding lists?

Esmail ebonak at hotmail.com
Thu Apr 23 13:01:46 EDT 2009


> My solution, I know the 'zip' version is more elegant, this is just for 
> fun:)
>  
>  >>> items = ['apple', 'car', 'town', 'phone']
>  >>> values = [5, 2, 7, 1]
>  >>> new_values = sorted(values, reverse = True)
>  >>> new_items = [items[x] for x in [i for i in map(values.index, 
> new_values)]]
>  >>> print(new_values)
> [7, 5, 2, 1]
>  >>> print(new_items)
> ['town', 'apple', 'car', 'phone']
>  >>>
>  

Cool .. always good to know alternative ways of accomplishing
a task.

Esmail




More information about the Python-list mailing list