Hello,
My input is two dictionaries that have string keys and integer values. I want to add the two dictionaries so that the result has all the keys of the input dictionaries, and the values are the sum of the input dictionaries' values.
For clarity, if a key appears in only one of the inputs, that key/value will appear in the result, whereas if the key appears in both dictionaries, the sum of values will appear in the result.
For example, say my input is:
a = dict()
a['cat'] = 1
a['fish'] = 10
a['aardvark'] = 1000
b = dict()
b['cat'] = 2
b['dog'] = 200
b['aardvark'] = 2000
I would like the result to be:
{'cat': 3, 'fish': 10, 'dog': 200, 'aardvark': 3000}
Knowing Python there must be a one-liner to get this done (it doesn't really have to be one line...). Any thoughts?