python按照list中的字典的某key排序

 python按照list中的字典的某key排序:

versionInfo=[{'version': 'v2.0', 'message': 'hehe 2.0', 'createTime': '2020-06-08 11:59:18'}, {'version': 'v1.2', 'message': 'v1.2', 'createTime': '2020-05-29 14:30:58'}, {'version': 'v1.1', 'message': 'version 1.1', 'createTime': '2020-05-29 14:30:08'}]
new_s = sorted(versionInfo, key=lambda e: e.__getitem__('createTime'))

 

s = [k for k, v in versionlist.items() if v == max(versionlist.values())]  # 根据字典的值(最新日期)获取key

 

你可能感兴趣的:(Python,按照list中的字典key,按照list中的字典排序)