今天爱分享给大家带来python如何根据dict内值排序一个列表中的所有dict【面试题详解】,希望能够帮助到大家。
如何排序如下列表,根据name或age
[{'name':'Homer', 'age':39}, {'name':'Bart', 'age':10}]
简单的做法;
newlist = sorted(list_to_be_sorted, key=lambda k: k['name'])
高效的做法
from operator import itemgetter
newlist = sorted(list_to_be_sorted, key=itemgetter('name'))
原文链接:https://itblood.website/4458.html,转载请注明出处。

![特工17 V0.25.9 官方中文版[更新][PC+安卓][4.6G] [亚洲风SLG/中文/动态CG]](/wp-content/uploads/replace/2025/07/19/51a26a58f2a0426bf9d7afd74af5291e.webp)