3 ms·
The examples were good, so it's worse than just "yet another python page filled with ads". But I'll summarize them: * First example, merge with update: #
by dr_zoidberg 7y ago
The examples were good, so it's worse than just "yet another python page filled with ads". But I'll summarize them:
* First example, merge with update:
# d1 and d2 being dicts
d3 = d1.copy()
d3.update(**d2)
* Second example, using dict():
d3 = dict(d1, **d2)
* Third example (3.9 onwards):
d3 = d1 | d2
# or
d3 = d1.copy()
d3 |= d2
The examples also show how each operation works (tl;dr: last value assigned to a key "wins").