[Python-ideas] Dict joining using + and +=

MRAB python at mrabarnett.plus.com
Wed Feb 27 13:14:38 EST 2019


On 2019-02-27 17:37, Guido van Rossum wrote:
> On Wed, Feb 27, 2019 at 9:34 AM George Castillo <gmcastil at gmail.com 
> <mailto:gmcastil at gmail.com>> wrote:
> 
>         The key conundrum that needs to be solved is what to do for `d1
>         + d2` when there are overlapping keys. I propose to make d2 win
>         in this case, which is what happens in `d1.update(d2)` anyways.
>         If you want it the other way, simply write `d2 + d1`.
> 
> 
>     This would mean that addition, at least in this particular instance,
>     is not a commutative operation.  Are there other places in Python
>     where this is the case?
> 
> 
> Yes there are. 'a' + 'b' is not the same as 'b' + 'a'.
> 
> For non-numbers we only require + to be associative, i.e. a + b + c == 
> (a + b) + c == a + (b + c).
> 
> That is satisfied for this proposal.
> Are there any advantages of using '+' over '|'?


More information about the Python-ideas mailing list