Code looks very lengthy, is there more elegant way to solve this, i am just a beginner.
# NOTE: Don't use any packages, i know it can be solved by importing counter from collections
d1 = {'a': 100, 'b': 200, 'c':300}
d2 = {'a': 300, 'b': 200, 'd':400}
d={}
for i,j in d1.items():
for k,l in d2.items():
if i==k:
c={i:j+l}
d.update(c)
for i,j in d1.items():
if i not in d:
d.update({i:j})
for m,n in d2.items():
if m not in d:
d.update({m:n})
Expected output:
output: {'a': 400, 'b': 400, 'c': 300, 'd': 400}