python - 基于python中的单个列表对多个列表进行排序

标签 python list

我正在打印一些列表,但这些值没有排序。

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)

根据“文件名”中的值对所有这些列表进行排序的最佳方法是什么?

如果:

filename = ['f3','f1','f2']
human_rating = ['1','2','3']
etc.

然后排序会返回:

filename = ['f1','f2','f3']
human_rating = ['2','3','1']
etc.

最佳答案

我会压缩然后排序:

zipped = zip(filename, human_rating, …)
zipped.sort()
for row in zipped:
     print "{:>6s}{:>5.1f}…".format(*row)

如果你真的想取回单独的列表,我会按上面的方式对它们进行排序,然后解压缩它们:

filename, human_rating, … = zip(*zipped)

关于python - 基于python中的单个列表对多个列表进行排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11601961/

相关文章:

python - 如何为 Pandas 创建滚动的每月日期时间索引?

Crontab : rm: cannot remove, 中的 Python 脚本没有这样的文件或目录

flutter - Dart/Flutter 按多个字段对列表进行排序

c# - List.Contains 未按预期工作

python - 将列表元素插入列表列表的 Pythonic 方法?

python - "Can' t 不同大小 vector 值之间的转换"

python - 与 Celery 任务共享 Pyramid 的数据库 session

html - 如何使 div 框彼此高度相同,同时在其中对齐列表项

Python/Google Drive API - orderBy 'name' 和 orderBy 'name_natural' 之间有什么区别?

javascript - 如何通过 JavaScript 将 [list] BBCode 转换为 HTML?