2つの辞書をマージ
2つの辞書をマージするには以下のような方法があります。
d1 = {'a': 1} d2 = {'b': 2}
**を使う方法。
print({**d1, **d2})
items()と|を使う方法。
print(dict(d1.items() | d2.items()))
update()
を使う方法。
d1.update(d2) print(d1)
2つの辞書をマージするには以下のような方法があります。
d1 = {'a': 1} d2 = {'b': 2}
**を使う方法。
print({**d1, **d2})
items()と|を使う方法。
print(dict(d1.items() | d2.items()))
update()
を使う方法。
d1.update(d2) print(d1)