import operator
dt = [{
"num":1,
"a":212
},{
"num":3,
"a":2112
},{
"num":2,
"a":2121
},{
"num":6,
"a":2122
}]
print(sorted(dt, key=operator.itemgetter("a")))
>>>[{'num': 1, 'a': 212}, {'num': 3, 'a': 2112}, {'num': 2, 'a': 2121}, {'num': 6, 'a': 2122}]
[python] dict按key排序 itemgetter
最新推荐文章于 2024-04-08 18:39:01 发布
关键词由CSDN通过智能技术生成