I am strong -1 on the proposal. The plus operation on two dictionaries feels far more natural as a vectorised merge, were it to mean anything. E.g., I'd expect
>>> {'a': 5, 'b': 4} + {'a': 3, 'b': 1} {'a': 8, 'b': 5} However, the hypothetical behavior when different keys are present would not be obvious to me. Obviously I can think of several possible behaviors, but none are the "one obvious thing." What would NOT feel intuitive is the operation meaning .update(). I do not have any particular objection to the union operator '|' being used for this purpose that is far more similar to set union... But neither do I see any great need for the shortcut. On Sat, Oct 19, 2019, 1:43 PM Christopher Barker <python...@gmail.com> wrote: > +1 on this, it seems very natural to me. > > I don’t mean to downplay the concerns people have, but in my experience > teaching newbies, dictionaries take some time to wrap their heads around > anyway. So yes, they may be confused when + removes data, but they’d be > confused anyway :-) > > And it would be less confusing than: > > {**d1, **d2} > > That means pretty much nothing to a newbie, and even if they do get what > ** means, it’s still some version of “put the contents of these two ducts > together” — I can’t see how that is any less confusing than d1+d2. > > As for expecting it to be lossless like list addition — if you don’t > understand that ducts can’t have duplicate keys, you’re don’t “get” dicts > anyway. > > >> The problem is that dicts are complex objects with two pieces of >> >> information, > > > And they are with or without +, of course. > > > > Even better, if we had two engineers (key) named Anita and Carolyn > (values) and combined them into a group, do you expect one of them to > vanish? > > Then a dict is not the data structure in which to store this data, plain > and simple. > > You don’t use a key like “engineer” if you might have more than one > engineer! > > This is completely independent of syntax. > > -CHB > > > -- > Christopher Barker, PhD > > Python Language Consulting > - Teaching > - Scientific Software Development > - Desktop GUI and Web Development > - wxPython, numpy, scipy, Cython > _______________________________________________ > Python-ideas mailing list -- python-ideas@python.org > To unsubscribe send an email to python-ideas-le...@python.org > https://mail.python.org/mailman3/lists/python-ideas.python.org/ > Message archived at > https://mail.python.org/archives/list/python-ideas@python.org/message/2LDA5UFD5M273SE2WOWWUHLZWJX5N3LC/ > Code of Conduct: http://python.org/psf/codeofconduct/ >
_______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/576VARHAK6VPGLCGMAI4VFWYRA3ILSTT/ Code of Conduct: http://python.org/psf/codeofconduct/