dica={'a':1,'b':2,'c':3,'d':4,'f':"hello"}
dicb={'b':3,'d':5,'e':7,'m':9,'k':'world'}
dic={}
for key in dica:
if dicb.get(key):
dic[key]=dica[key]+dicb[key]
else:
dic[key]=dica[key]
for key in dicb:
if dica.get(key):
pass
else:
dic[key]=dicb[key]
print(dic)
下面是运行结果
{'d': 9, 'k': 'world', 'e': 7, 'm': 9, 'f': 'hello', 'b': 5, 'c': 3, 'a': 1}