sorting multiple lists based on a single list in python
list, python
Solution
I would zip then sort:
zipped = zip(filename, human_rating, …)
zipped.sort()
for row in zipped:
print "{:>6s}{:>5.1f}…".format(*row)
If you really want to get the individual lists back, I would sort them as above, then unzip them:
filename, human_rating, … = zip(*zipped)
Problem
I'm printing a few lists but the values are not sorted. ``` for f, h, u, ue, b, be, p, pe, m, me in zip(filename, human_rating, rating_unigram, percentage_error_unigram, rating_bigram, percentage_error_bigram, rating_pos, percentage_error_pos, machine_rating, percentage_error_machine_rating): print "{:>6s}{:>5.1f}{:>7.2f}{:>8.2f} {:>7.2f} {:>7.2f} {:>7.2f} {:>8.2f} {:>7.2f} {:>8.2f}".format(f,h,u,ue,b,be,p,pe,m,me) ``` What's the best way to sort all of these lists based on the values in 'filename'? So if: ``` filename = ['f3','f1','f2'] human_rating = ['1','2','3'] etc. ``` Then sorting would return: ``` filename = ['f1','f2','f3'] human_rating = ['2','3','1'] etc. ```