An alternative way of doing this (if you have python 2.4):

>>> ppl =   ['john', 'mary', 'lary', 'jane']
>>> age =   [15, 30, 23, 25]
>>> height= [160, 165, 178, 170]


>>> sortby = lambda a, b: [a[b.index(x)] for x in sorted(b)]

>>> sortby(ppl, age)
['john', 'lary', 'jane', 'mary']
>>> sortby(ppl, height)
['john', 'mary', 'jane', 'lary']

>>> age    # age is not changed
[15, 30, 23, 25]

 

_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to