I have a dict as below:
dict_data = {
"NAME": ['A', 'B', 'A', 'B', 'C', 'C'],
"VALUE": [100, 200 , 100 , 200, 300, 300]
}
How to sum values from above dict if NAME duplicate output:
NAME: A
VALUE: 200
NAME: B
VALUE: 400
NAME: C
VALUE: 600
or output to with list:
[A, B, C]
[200, 400, 600]
i using as below:
data = dict.fromkeys(dict_data['NAME'], 0) #create a new dict from value "NAME" of DICT_DATA
for NAME, VALUE in zip(dict_data['NAME'], dict_data['VALUE']):
data[NAME] += value # Dict NAME A + Dict Name A,... similar to B and C
for key,value in data.items():
print(list(key))
print(list(value))