快速合并两个字典

x = {'a':1, 'b':3}
y = {'c': 5, 'd': 8}
z = dict(list(x.items()) + list(y.items()))
print(z)
# {'d': 8, 'c': 5, 'a': 1, 'b': 3}

python 3.5之后更简便的方法:

x = {'a':1, 'b':3}
y = {'c': 5, 'd': 8}
#z = dict(list(x.items()) + list(y.items()))
z = {**x, **y}
print(z)

 

转载于:https://www.cnblogs.com/fengxuemuyangren/p/11039763.html

你可能感兴趣的:(快速合并两个字典)