[Python-ideas] Dict joining using + and +=
Guido van Rossum
guido at python.org
Wed Feb 27 12:37:00 EST 2019
On Wed, Feb 27, 2019 at 9:34 AM George Castillo <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.
--
--Guido van Rossum (python.org/~guido)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20190227/ffaeec68/attachment-0001.html>
More information about the Python-ideas
mailing list