solution by jadec.se...@gmail.com<mhtml:{154E1F55-D942-4CE9-9B8C-82060E1E80CE}mid://00000047/!x-usc:mailto:jadec.se...@gmail.com>, China
values,items = zip( *sorted( zip (values,items))) ----- Original Message ----- From: "Esmail" <ebo...@hotmail.com<mhtml:{154E1F55-D942-4CE9-9B8C-82060E1E80CE}mid://00000047/!x-usc:mailto:ebo...@hotmail.com> > To: <python-list@python.org<mhtml:{154E1F55-D942-4CE9-9B8C-82060E1E80CE}mid://00000047/!x-usc:mailto:python-list@python.org> > Sent: Tuesday, April 21, 2009 12:10 AM Subject: sorting two corresponding lists? > Hello all, > > I wonder if someone could help me with sorting two corresponding lists. > > For instance 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] > > 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] > > So I would like to keep the corresponding value still corresponding > after the sorting. > > Is there an easy/nice/Pythonic way to do this? > > Thanks, > Esmail > > -- > http://mail.python.org/mailman/listinfo/python-list<mhtml:{154E1F55-D942-4CE9-9B8C-82060E1E80CE}mid://00000047/!x-usc:http://mail.python.org/mailman/listinfo/python-list>
-- http://mail.python.org/mailman/listinfo/python-list