python - 在 python 中 - 在嵌套字典中查找最大日期

标签 python

我有一个字典,如下所示。

对于键 '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/

相关文章:

python - 如何使用 Pandas 在年份变化时继续周数

python - 获取 token 以使用 Python 将表单识别器自定义模型从一个帐户共享到另一个帐户

python - 使用Qt Gui进行实时视频源的Opencv人脸检测速度较慢

python - 继续获取,类型错误 : a float is required

python - 如何检查服务器上安装的 wxPython 版本?

python numpy ValueError : operands could not be broadcast together with shapes

python - 从 MultiIndex 中选择特定级别

python - 使用 python-zmq 的多个 ipc 发布者和一个订阅者

python - OpenCV HOGDescriptor.compute 错误

python - python中的参数模块?从对象导入函数