dict1 = {a: 5, b: 7} dict2 = {a: 3, c: 1} result {a:8, b:7, c:1}
How can I get the result?
A quick dictionary comprehension that should work on any classes which accept the + operator. Performance might not be optimal.
{ **dict1, **{ k:(dict1[k]+v if k in dict1 else v) for k,v in dict2.items() } }