[Python-ideas] PEP: Dict addition and subtraction

Greg Ewing greg.ewing at canterbury.ac.nz
Fri Mar 8 18:32:15 EST 2019

Guido van Rossum wrote:
> I guess this explains the behavior of removing results <= 0; it makes 
> sense as multiset subtraction, since in a multiset a negative count 
> makes little sense. (Though the name Counter certainly doesn't seem to 
> imply multiset.)

It doesn't even behave consistently as a multiset, since c[k] -= n
is happy to let the value go negative.

> For sets, 
> union and intersection are distributive over each other.

> Note that this is *not* the case for + and * when used with 
> (mathematical) numbers... So in a sense, SETL (which uses + and *
 > for union and intersection got the operators wrong.

But in another sense, it didn't. In Boolean algebra, "and" and "or"
(which also distribute over each other) are often written using the
same notations as multiplication and addition. There's no rule in
mathematics saying that these notations must be distributive in one
direction but not the other.


More information about the Python-ideas mailing list