>>> s
[{'id': 3}, {'id': 1}, {'id': 2}]
>>> sorted(s, cmp = lambda x,y:cmp(x["id"],y["id"]))
[{'id': 1}, {'id': 2}, {'id': 3}]
>>>
Python sorted 对字典列表
最新推荐文章于 2021-11-11 23:53:02 发布
>>> s
[{'id': 3}, {'id': 1}, {'id': 2}]
>>> sorted(s, cmp = lambda x,y:cmp(x["id"],y["id"]))
[{'id': 1}, {'id': 2}, {'id': 3}]
>>>