> > Esmail wrote: > > > items = [apple, car, town, phone] > > values = [5, 2, 7, 1] > > > > I would like to sort the 'items' list based on the 'values' list so > > that I end up with the following two list: > > > > items = [town, apple, car, phone] > > values = [7, 5, 2, 1]
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'] >>> cheers! tiefeng wu 2009-04-22
-- http://mail.python.org/mailman/listinfo/python-list