1.两个字典里面的key一样,顺序不一样,怎样实现两个字典相同的key的值相加那?
from collections import Counter
def addTwoDicTogether():
x = {'小明': 1, '小黑': 2}
y = {'小黑': 10, '小鱼': 11}
X, Y = Counter(x), Counter(y)
z = dict(X + Y)
print(z)
addTwoDicTogether()
输出:
{'小鱼': 11, '小明': 1, '小黑': 12}