Merge with overlapping keys
Input
merge_sum([{'a': 1, 'b': 2}, {'b': 3, 'c': 4}])
Output
{'a': 1, 'b': 5, 'c': 4}
Key 'b' appears in both dictionaries, so its values are summed (2 + 3 = 5). Keys appear in order a, b, c based on first occurrence.
Full lesson preview
Combine multiple dictionaries into one by summing values for matching keys.
Problem statement
Task
Examples
Input
merge_sum([{'a': 1, 'b': 2}, {'b': 3, 'c': 4}])
Output
{'a': 1, 'b': 5, 'c': 4}
Key 'b' appears in both dictionaries, so its values are summed (2 + 3 = 5). Keys appear in order a, b, c based on first occurrence.
Input format
Output format
Constraints
Samples
Input
merge_sum([{'x': 10}, {'y': 5}, {'x': 2, 'z': 1}])
Output
{'x': 12, 'y': 5, 'z': 1}
x occurs twice and is summed (10 + 2 = 12); y and z appear once.