python_函数式编程_sorted_按照成绩总和对学生信息报进行排序

import functools
# from functools import cmp_to_key

students = [{"name": 'eric', "score": [70, 50, 40]},
            {"name": 'ben', "score": [70, 90, 40]},
            {"name": 'gavin', "score": [70, 100, 189]}
            ]


def func_a(x, y):
    return sum(x["score"]) - sum(y["score"])


result = sorted(students, key=functools.cmp_to_key(func_a))
print(result)

你可能感兴趣的:(py_函数式编程(高阶函数))