5 ms·
Why not use `update` in Python? e.g. if you want to merge dictA and dictB, you'd write dictA.update(dictB) If you have many you can always use this:
by ivan_ah 9y ago
Why not use `update` in Python? e.g. if you want to merge dictA and dictB, you'd write
dictA.update(dictB)
If you have many you can always use this:
dictD = {}
map(dictD.update, [dictA, dictB, dictC])
- vanni 9y agoOr dictAB = dict(dictA, **dictB) in Python 2 and 3.
- dom0 9y agoThat'll create an intermediate dict (due to the unpacking) for Python <3.6 and then another dict. a.update(b) does neither. It also has different semantics from a.update(b). The unpacking way will explode when both a and b contain the same key, while a.update(b) does not; existing keys also contained in b will be overwritten by the values from b.