Python 多个List按照某一个List进行排序
Oct. 17, 2018, 3:09 p.m.
read: 1495
实际场景是:
现在有三个list
分别是list1 list2 list3,分别代表学生的姓名,学号,成绩
现在需要按照成绩排序,也就是:
list 1, list 2, 按照list 3的顺序进行排序,给出代码:
data = [(score, name, name2) for score, name, name2 in zip(list_3, list_1, list_2)]
data.sort()
list_3 = [score for score, name, name2 in data]
list_1 = [name for score, name, name2 in data]
list_2 = [name2 for score, name, name2 in data]