我有一个字典,如下所示。
对于键 '10000ag2' 和 10000ag1',找出哪个键具有最大日期的 last_event 的最有效方法是什么?
{'10000ag2':
{'last_view': datetime.datetime(2012, 4, 24, 8, 27, 30),
'last_event': datetime.datetime(2012, 4, 24, 8, 28, 30),
'last_prid': '300'},
'10000ag1':
{'last_view': datetime.datetime(2012, 4, 24, 8, 27, 30),
'last_event': datetime.datetime(2012, 4, 24, 8, 28, 30),
'last_prid': '300'}}
我希望得到一份 list ,例如20 个顶级 key 。
谢谢
最佳答案
max(my_dict.items(), key=lambda x: x[1]['last_event'])[0]
关于python - 在 python 中 - 在嵌套字典中查找最大日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10296251/