Merging two Python dictionaries, summing the values of matching elements?
- by jamieb
Given two dictionaries, like so:
q1_sales = {'Bob': 21000, 'Charles': 18000, 'John': 35000, 'Sam': 14000}
q2_sales = {'Bob': 22000, 'John': 33000, 'Sam': 23000}
What's the most pythonic way to produce this?
total_sales = {'Bob': 43000, 'Charles': 18000, 'John': 68000, 'Sam': 37000}
Thanks!