On Tue, Oct 22, 2019 at 12:05 AM Jan Greis <jan.r.gr...@gmail.com> wrote:
> On 21/10/2019 21:14, Dominik Vilsmeier wrote: > > Exactly, so the dict "+" behavior would match the set "|" behavior, > preserving the keys. But how many users will be concerned about whether the > keys are going to be preserved? I guess almost everybody will want to know > what happens with the values, and that question remains unanswered by just > looking at the "+" or "|" syntax. It's reasonable to assume that values are > preserved as well, i.e. `d1 + d2` adds the missing keys from `d2` to `d1`. > Of course, once you know that "+" is actually similar to "update" you can > infer that the last value wins. > > There's one reason for + which I feel is being missed (though I think > someone may have briefly mentioned it last time this topic was brought > up): If we look at the behaviour of dict literals, adding two dicts > actually behaves like concatenation in the sense that > > {"key1": "val1", "key2": "val2", "key1": "val3"} == {"key1": "val3", > "key2": "val2"} > > which is exactly what we would get by adding {"key1": "val1", "key2": > "val2"} and {"key1": "val3"} > It is not a "concatenation" though, because you lost {"key1": "val1"} in the process. The concatenation is not _just_ "writing something after something", you can do it with anything, but the actual operation, producing the result. Richard > > so using + we would actually have > > {"key1": "val1", "key2": "val2"} + {"key1": "val3"} == {"key1": "val1", > "key2": "val2", "key1": "val3"} > _______________________________________________ > 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/IRU66KNSTIG2FYE2KCGTCZHWYT22HC44/ > 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/DSPL3DQXUYIDWR3QCOE7FFMPHDXMGTNI/ Code of Conduct: http://python.org/psf/codeofconduct/