快速合并两个字典

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)

 

posted @ 2019-06-17 15:07  丨牧羊人  阅读(1012)  评论(0编辑  收藏  举报