Merging two Python dictionaries, summing the values of matching elements?
Posted
by jamieb
on Stack Overflow
See other posts from Stack Overflow
or by jamieb
Published on 2010-03-09T01:23:39Z
Indexed on
2010/03/09
1:36 UTC
Read the original article
Hit count: 498
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!
© Stack Overflow or respective owner