python列表嵌套字典,根据字典键对值进行排序

 

a=[{'balance': '1,500', 'cpm': '12.43',  'expSumTotal': 53029929}, {'balance': '24,000', 'cpm': '11.41', 'expSumTotal': 2395}, {'balance': '28,000', 'cpm': '21.4', 'expSumTotal': 53029930}]

a.sort(lambda a, b: b["expSumTotal"] - a["expSumTotal"])  # 从大到小排序

 

 

a = {'a':4,'b':28,'c':99,'d':100}

print(a.items())

data = sorted(a.items(), key=lambda x: x[1])

print(data)

 

entries = [{'date':'20181209','os':'ios'},{'date':'20181210','age':18},{'date':'20181201','gender':'man'}]

# entries.sort(lambda a, b: b["date"] - a["date"])

entries.sort(key=lambda x: x['date'], reverse=True)

print(entries)

 

更多参照

https://blog.csdn.net/xiuduyi/article/details/48622835

你可能感兴趣的:(python列表嵌套字典,根据字典键对值进行排序)