<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto">Here is a working implementation of dictionary addition, for consideration with the PEP:<div><br></div><div><a href="https://bugs.python.org/issue36144">https://bugs.python.org/issue36144</a><br><div><br><div id="AppleMailSignature" dir="ltr">Brandt</div><div dir="ltr"><br>On Feb 27, 2019, at 16:07, Guido van Rossum <<a href="mailto:guido@python.org">guido@python.org</a>> wrote:<br><br></div><blockquote type="cite"><div dir="ltr"><div dir="ltr">OK, you're it. Please write a PEP for this.<br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Feb 27, 2019 at 3:53 PM Steven D'Aprano <<a href="mailto:steve@pearwood.info">steve@pearwood.info</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Wed, Feb 27, 2019 at 10:34:43AM -0700, George Castillo wrote:<br>
> ><br>
> > The key conundrum that needs to be solved is what to do for `d1 + d2` when<br>
> > there are overlapping keys. I propose to make d2 win in this case, which is<br>
> > what happens in `d1.update(d2)` anyways. If you want it the other way,<br>
> > simply write `d2 + d1`.<br>
> <br>
> <br>
> This would mean that addition, at least in this particular instance, is not<br>
> a commutative operation. Are there other places in Python where this is<br>
> the case?<br>
<br>
Strings, bytes, lists, tuples.<br>
<br>
In this case, I wouldn't call it dict addition, I would call it a union <br>
operator. That suggests that maybe we match sets and use | for union.<br>
<br>
That also suggests d1 & d2 for the intersection between two dicts, but <br>
which value should win?<br>
<br>
More useful than intersection is, I think, dict subtraction: d1 - d2 <br>
being a new dict with the keys/values from d1 which aren't in d2.<br>
<br>
<br>
<br>
-- <br>
Steven<br>
_______________________________________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org" target="_blank">Python-ideas@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-ideas" rel="noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/python-ideas</a><br>
Code of Conduct: <a href="http://python.org/psf/codeofconduct/" rel="noreferrer" target="_blank">http://python.org/psf/codeofconduct/</a><br>
</blockquote></div><br clear="all"><br>-- <br><div dir="ltr" class="gmail_signature">--Guido van Rossum (<a href="http://python.org/~guido" target="_blank">python.org/~guido</a>)</div>
</div></blockquote><blockquote type="cite"><div dir="ltr"><span>_______________________________________________</span><br><span>Python-ideas mailing list</span><br><span><a href="mailto:Python-ideas@python.org">Python-ideas@python.org</a></span><br><span><a href="https://mail.python.org/mailman/listinfo/python-ideas">https://mail.python.org/mailman/listinfo/python-ideas</a></span><br><span>Code of Conduct: <a href="http://python.org/psf/codeofconduct/">http://python.org/psf/codeofconduct/</a></span><br></div></blockquote></div></div></body></html>