I have a list :
x = [[17, 2], [18, 4], [17, 2], [18, 0], [19, 4],
[17, 4], [19, 4], [17, 4], [20, 4], [17, 4],
[20, 4], [17, 4], [17, 4], [18, 4], [17, 4]]
I'd like to sum all second value when the first is the same.
Ex : 17 = 28...
I try to make a dict with :
d = {}
for row in x:
if row[0] not in d:
d[row[0]] = []
d[row[0]].append(row[1])
The result is
{17: [2, 2, 4, 4, 4, 4, 4, 4],
18: [4, 0, 4], 19: [4, 4],
20: [4, 4]}
I didn't find a way to sum the values.