我的字典是这样的:
docScores = {0:[{u'word':2.3},{u'the':8.7},{u'if':4.1},{u'Car':1.7}],
1:[{u'friend':1.2},{u'a':5.2},{u'you':3.8},{u'person':0.8}],
...
29:[{u'yard':1.5},{u'gardening':2.8},{u'paint':3.7},{u'brush':1.6}]
}
我想对每个列表的每个内部字典的值求和并将其存储在一个新字典中,新字典的键值为{0:2.3+8.7+4.1+1.7, 1:1.2+5.2+3.8+0.8, ... etc}
ie
for x in docScores[0]: #{0:
for x in docScores[0][0].values(): #{,2.3}.
sum = sum+x #where sum = 0 before loop
docSum[0] = sum
repeat this loop for every document
我尝试过的任何变化都会给我带来意想不到的输出。谁能给我正确的语法?