Hacker News new | past | comments | ask | show | jobs | submit login

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




Great 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.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: