kenwoodjw/python_interview_question

9.请按alist中元素的age由大到小排序

xingdongzhe opened this issue · 1 comments

使用itemgetter 更优雅

from operator import itemgetter
alist = [{'name': 'a', 'age': 20}, {'name': 'b', 'age': 30}, {'name': 'c', 'age': 25}]
alist_sorted = sorted(alist, key=itemgetter('age'), reverse=True)

可以提交pr