
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"} so using + we would actually have {"key1": "val1", "key2": "val2"} + {"key1": "val3"} == {"key1": "val1", "key2": "val2", "key1": "val3"}