【发布时间】:2019-08-02 09:04:01
【问题描述】:
我有一个这样的字典:
{
'first':{'value': 2, 'blah': 'ants'},
'second':{'value': 5, 'blah': 'birds'},
'third':{'value': 8, 'blah': 'cats'},
'fourth':{'value': 10, 'blah': 'cats'}
}
我希望输出为 25,即(2+5+8+10)
我该怎么做?
【问题讨论】:
-
到目前为止你有什么尝试?如果您不知道如何在 Python 中迭代字典,请查看 Iterating over dictionaries using 'for' loops。
-
您遍历 dict 并将值相加。
标签: python json list dictionary