Quantcast
Channel: Hacking Corner
Viewing all articles
Browse latest Browse all 20

Python: sort two lists - second in the same order as first

$
0
0

[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]


Viewing all articles
Browse latest Browse all 20

Trending Articles