I have a list of dictionary in this form :
[
{'signal_8': 1, 'signal_1': 7, 'signal_10': 5, 'signal_5': 2, 'signal_2': 5, 'signal_6': 3, 'signal_4': 9, 'signal_3': 6, 'signal_9': 4, 'signal_7': 8},
{'signal_8': 1, 'signal_1': 7, 'signal_10': 5, 'signal_5': 2, 'signal_2': 5, 'signal_6': 3, 'signal_4': 9, 'signal_3': 6, 'signal_9': 4, 'signal_7': 8},
{'signal_8': 1, 'signal_1': 7, 'signal_10': 5, 'signal_5': 2, 'signal_2': 5, 'signal_6': 3, 'signal_4': 9, 'signal_3': 6, 'signal_9': 4, 'signal_7': 8},
]
and I want to sum the values in this by key for each element in the list like that :
{
'signal_8': 3,
'signal_1': 21,
'signal_10': 15,
'signal_5': 6,
'signal_2': 15,
'signal_6': 9,
'signal_4': 27,
'signal_3': 18,
'signal_9': 12,
'signal_7': 24
}
what I have tried is the following :
result = {}
sm = 0
for elm in original_list:
for k,v in elm.items():
sm += v
result[k] = sm
print(result)
but it still doesn't work.
See Question&Answers more detail:
os