python - 获取内部字典中的至少三个值(Python 3.4)

标签 python dictionary key min

我的字典值是这样的:

曼哈顿[imagePath1][imagePath2] = img2manhattan

那么如何获取至少三个值的键作为列表呢? (在 imagePath2 键中)

(我想获取第一个最小值的键+第二个最小值的键+第三个最小值的键作为列表。)

最佳答案

我会这样做:

d = dict(manhattan[imagePath1][imagePath2])
min_keys = []
for i in xrange(3):
    min_keys.append(min(d,key=d.get))
    del d[min_keys[-1]] 

在此 min_keys 包含您需要的内容之后。

关于python - 获取内部字典中的至少三个值(Python 3.4),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47411649/

相关文章:

python - 在线程中捕获键盘中断或处理信号

python - 抓取 Facebook 广告库报告

java - 如何计算java中对象列表的变量?

json - 在Bash中使用jq按对象属性值的长度降序对它们进行排序

javascript - ng-if 中的原始 javascript 不起作用?

python - Django 说字段不存在时它确实存在

Python:如何在我的时间序列中删除每天的前 5 分钟?

python - 类型错误 : Format Requires Mapping

dictionary - 存储具有重复键的键值对的数据结构

Java - 属性 : Add new keys to properties file in run time?