请教大神,有什么快速的排序方法吗 [{"a":3,"b":"ggg"},{"a":1,"b":"fff"},{"a":2,"b":"eee"}] 按照 [2,1,3] 排序 输出[{"a":2,"b":"eee"},{"a":1,"b":"fff"},{"a":3,"b":"ggg"}]
1
myyou 2019-03-13 14:07:58 +08:00
sorted([{"a":3,"b":"ggg"},{"a":1,"b":"fff"},{"a":2,"b":"eee"}], key=lambda x: [2, 1, 3].index(x["a"]))
|
3
wqzjk393 2019-03-13 14:17:56 +08:00
有个比较特别的方法。读进 pandas.dataframe。df = pandas.dataframe(values=dict.value,names=dict.keys) df=df.sorted(by='a'),然后再包装成一个字典返回去
|