<div dir="ltr"><div dir="ltr"><br></div><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Mar 6, 2019 at 4:01 PM Chris Angelico <<a href="mailto:rosuav@gmail.com" target="_blank">rosuav@gmail.com</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 Thu, Mar 7, 2019 at 10:52 AM Josh Rosenberg<br>
<<a href="mailto:shadowranger%2Bpythonideas@gmail.com" target="_blank">shadowranger+pythonideas@gmail.com</a>> wrote:<br>
><br>
> Allowing dicts to get involved in + means:<br>
<br>
Lots of words that basically say: Stuff wouldn't be perfectly pure.<br>
<br>
But adding dictionaries is fundamentally *useful*. It is expressive.<br></blockquote><div><br></div><div>It is useful.  It's just that + is the wrong name.</div><div><br></div><div>Filtering and subtracting from dictionaries are also useful!  Those are operations we do all the time.  It would be useful if & and - did these things too—and if we have & and -, it's going to be even more obvious that the merge operator should have been |.</div><div><br></div><div><br></div><div>Josh Rosenberg <<a href="mailto:shadowranger%2Bpythonideas@gmail.com" target="_blank">shadowranger+pythonideas@gmail.com</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">If we were inventing programming languages in a vacuum, you could say + can mean "arbitrary combination operator" and it would be fine. But we're not in a vacuum; every major language that uses + with general purpose containers uses it to mean element-wise addition or concatenation, not just "merge".</blockquote><div><br></div><div>If we were inventing Python from scratch, we could have decided that we always use "+" to combine collections.  Sets would combine with + and then it would make sense that dictionaries also combine with + .</div><div><br></div><div>But that is not Python.  Lists combine with + and sets combine with |.  Why?  Because lists add (put both collections together and keep everything), but sets merge (put both collections together and keep some).</div><div><br></div><div><div>So, Python already has a merge operator.  The merge operator is "|".</div><div><br></div><div>For lists, += is shorthand for list.extend().<br></div></div><div>For sets, |= is shorthand for set.update().</div><div><br></div><div>Is dictionary merge more like extend() or more like update()?  Python already took a position on that when it was decided to name the dictionary method update().  That ship sailed a long time ago.</div><div><br></div><div><br></div><div>—Ping</div><div><br></div></div></div>