快速合并两个字典

x = {'a':1, 'b':3}
y = {'c': 5, 'd': 8}
z = dict(list(x.items()) + list(y.items()))
print(z)<br>
# {'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)

猜你喜欢

转载自www.cnblogs.com/fengxuemuyangren/p/11039763.html