d = {**d1, **d2}
which arguably has all the visual benefits argued for. d = {**d1, **d2}
which arguably has all the visual benefits argued for.Few people would be able to guess what it means the first time they see it, or think of it as the "obvious way" to merge two dicts
[...]
{d1, d2} ignores the types of the mappings and always returns a dict. type(d1)({d1, d2}) fails for dict subclasses such as defaultdict that have an incompatible __init__ method.
Though I'm not personally convinced that + would be more obvious or that dict subtypes are merged often enough for this to matter.
It also mentions further down, that for lists er have both
a + b
and [*a, *b]
As well as other ones I hadn't even thought about like a[len(a):] = b.A symbol's property depend on the operation, the multiplication symbol for example is commutative in some cases and not in others.
But this convention is not at all respected in programming (e.g. + for string concatenation in many languages) so I have to admit that it's pretty irrelevant.
>>> [1,2,3] + [4,5,6]
[1, 2, 3, 4, 5, 6]
>>> [4,5,6] + [1,2,3]
[4, 5, 6, 1, 2, 3]
In dictionaries it would behave differently as well (duplicated keys, etc.)