Just being pedantic here :) [items[x] for x in [i for i in map(values.index, new_values)]]
Is the same as [items[x] for x in map(values.index, new_values)] -----Original Message----- From: python-list-bounces+hans.dushanthakumar=hcn.com...@python.org [mailto:python-list-bounces+hans.dushanthakumar=hcn.com...@python.org] On Behalf Of Esmail Sent: Friday, 24 April 2009 3:02 AM To: tiefeng wu Cc: python-list@python.org Subject: Re: sorting two corresponding lists? > 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 -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list