Removing duplicate keys from python dictionary but summing the values

duplicates, python

Solution

I'd like to improve Paul Seeb's answer:

tps = [('cat',5),('dog',9),('cat',4),('parrot',6),('cat',6)]
result = {}
for k, v in tps:
  result[k] = result.get(k, 0) + v

Problem

I have a dictionary in python ``` d = {tags[0]: value, tags[1]: value, tags[2]: value, tags[3]: value, tags[4]: value} ``` imagine that this dict is 10 times bigger, it has 50 keys and 50 values. Duplicates can be found in this tags but even then values are essential. How can I simply trimm it to recive new dict without duplicates of keys but with summ of values instead? `d = {'cat': 5, 'dog': 9, 'cat': 4, 'parrot': 6, 'cat': 6}` result `d = {'cat': 15, 'dog': 9, 'parrot': 6}`

Original source