我試圖總結多個詞典之間的值,例如:總結值
oneDic = {'A': 3, 'B': 0, 'C':1, 'D': 1, 'E': 2}
otherDic = {'A': 9, 'D': 1, 'E': 15}
我想總結一下oneDic
如果他們在發現的值otherDic
並且如果在otherDic
相應值小於特定值
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,因爲C
不otherDic
發現的E
在otherDic
值不小於value
但是當我運行這段代碼,我得到一個可愛的關鍵錯誤,任何人可以點我在正確的方向?
我喜歡比其他答案這更好,因爲明確的被測試兩個條件。 – Marius