[python]
labels = [ 'third', 'first', 'second' ]
values = [ 30, 10, 20 ]
z = sorted(zip(values,labels))
# z
# [(10, 'first'), (20, 'second'), (30, 'third')]
labels_sorted, values_sorted = zip(*z)
# labels_sorted
# (10, 20, 30)
# values_sorted
# ('first', 'second', 'third')
[/python]
↧
Python: sort two lists - second in the same order as first
↧