[Python-ideas] PEP: Dict addition and subtraction

MRAB python at mrabarnett.plus.com
Fri Mar 8 14:19:17 EST 2019


On 2019-03-08 16:55, Guido van Rossum wrote:
[snip]
> If we were to use "|" and "&" for dict "union" and "intersection", the 
> mutual distributive properties will hold.
> 
>     Since "|" (especially "|=") *is* suitable for "update", I think we
>     should reserve "+" for some future commutative extension.
> 
> 
> One argument is that sets have an update() method aliased to "|=", so 
> this makes it more reasonable to do the same for dicts, which also have 
> a. update() method, with similar behavior (not surprising, since sets 
> were modeled after dicts).
> 
[snip]
One way to think of it is that a dict is like a set, except that each of 
its members has an additional associated value.


More information about the Python-ideas mailing list