set operations on dictionaries?

aba cus cus_aba at
Mon Oct 16 20:10:14 CEST 2006

              It should be quite obvious what should happen when the values stored for
    the relevant keys are identical. It is less obvious (and needs some
    though) what should happen when the keys are the same in the two
    operands, but the values are different.

I think you answered you own proposal in the negative.  Precisely because
the result of this example

    {1: 10, 2: 20} | {2: 25, 3:30}

is ill-defined, Python shouldn't implement set operations on dictionaries.

"In the face of ambiguity, refuse the temptation to guess."

I understand this point but this is just an argument for saying that it should throw an exception when the values don't match. It is not an argument for not doing the logical thing when they do. In fact in many situations it can be reasonably expected that the values will be the same. If not, give an error. There is no danger in that. The programmer should know whether this is a reasonable expectation in any givn case.
(As it is at the moment, you get an error even if they match...)

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Python-list mailing list