我正试图在如下字典列表中获取最大值为'size'
的字典索引:
ld = [{'prop': 'foo', 'size': 100}, {'prop': 'boo', 'size': 200}]
使用以下代码,我可以选择最大大小:
items = [x['size'] for x in ld]
print(max(items))
我现在怎么能取它的索引呢?有简单的方法吗?
测试:
我想我能做到:
items = [x['size'] for x in ld]
max_val = max(items)
print(items.index(max_val))
是这样吗?
目前没有回答
相关问题 更多 >
编程相关推荐