I have a dictionary of names and ages. Some of the names are identical. I want to sum the age of the names that are identical.
My fake data looks like this:
pete: 33
ann: 7
ruth: 3
ann: 5
austin: 90
In the examples there are two anns. So I want to sum the ages of the two anns. Currently I have a dictionary:
dict = {'pete':33,'ann':7,'ruth':3,'ann':5,'austin':90}
My result should look like this
dict = {'pete':33,'ann':12,'ruth':3,'austin':90}
pete: 33
ann: 12
ruth: 3
austin: 90
I think to put the data in a dictionary like this isn't the best solution. What is a good other solution to store the data and process them into the output?