2つの辞書をすばやくマージ
1782 ワード
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