python list 嵌套 dict 按照字典中的单个key进行单级排序 或 按照多个键进行多级排序

student = [{"no": 1,"score": 90},{"no": 2,"score": 90},{"no": 3,"score": 88},{"no": 4,"score": 92}]

# 单级排序,仅按照score排序
student_sort_1 = sorted(student, key=lambda e: e.__getitem__('score'))

# 多级排序,先按照score,再按照no排序
student_sort_2 = sorted(student, key=lambda e:(e.__getitem__('score'), e.__getitem__('no')))
原文地址:https://www.cnblogs.com/lowmanisbusy/p/9124229.html