4 ms·
The PEP [1] addresses this: 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
by bobbiechen 7y ago
The PEP [1] addresses this:
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.
[1] https://www.python.org/dev/peps/pep-0584/#d1-d2 https://www.python.org/dev/peps/pep-0584/#d1-d2
- thomasahle 7y agoGreat PEP :-) 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.