Python基础-list中元素为字典的排序


from operator import itemgetter

lst = [ {'student_name': 'zhangsan', 'student_score': 65},
{'student_name': 'lisi', 'student_score': 95},
{'student_name': 'wangwu', 'student_score': 80},
{'student_name': 'maliu', 'student_score': 75},
{'student_name': 'zhuqi', 'student_score': 88} ]

top3 = sorted(lst, key=itemgetter('student_score'), reverse=True)[:3]

print top3

猜你喜欢

转载自blog.csdn.net/jamin2018/article/details/80103573