【发布时间】:2015-04-21 00:16:50
【问题描述】:
我正在尝试对多个字典之间的值求和,例如:
oneDic = {'A': 3, 'B': 0, 'C':1, 'D': 1, 'E': 2}
otherDic = {'A': 9, 'D': 1, 'E': 15}
我想总结oneDic中的值if它们在otherDic中找到如果otherDic中对应的值小于a具体值
oneDic = {'A': 3, 'B': 0, 'C':1, 'D': 1, 'E': 2}
otherDic = {'A': 9, 'D': 1, 'E': 15}
value = 12
test = sum(oneDic[value] for key, value in oneDic.items() if count in otherTest[count] < value
return (test)
我希望值为 4,因为在 otherDic 中找不到 C 并且 otherDic 中的 E 的值不小于 value
但是当我运行这段代码时,我得到了一个可爱的关键错误,有人能指出我正确的方向吗?
【问题讨论】:
标签: python dictionary sum iteration multiple-conditions