Hi Julien,<br><br>Having now looked at your code, I realize we are not talking about the same concepts at all.<br><br>What I meant is similar to set union on the keys, where if a key exists in both dicts, the value in the result is equal to one of the values in the operands (and if the value is the same for both operands, that value is also the result value).<br>

<br>But looking at your code, you are more interested in *elementwise* addition, so that {'x': 1} + {'x': 2} results in {'x': 3}, and missing keys are considered to be zero. (For disjoint key sets, your result is the same as mine. :-)<br>

<br>I think this would be a nice thing for some applications, but I'm doubtful that it's of enough interest to add to the standard library, let alone make it a standard feature of the built-in dict class. One problem is that the dict API is already very rich (dozens of methods and operations) Another problem is that your proposed class solves only part of the puzzle of elementwise operations -- if you have elementwise addition for dicts, why not for lists? But l1+l2 already has a meaning for list: concatenation. We've discussed this before. NumPy has got its own solution (a1+a2 does elementwise addition if a1 and a2 are NumPy arrays), but for the stdlib we've always decided that it's better to leave the choice up to the user, the app or the framework (like NumPy), instead of making a choice in the stdlib that causes backward incompatibility.<br>

<br>(Had I known all this 22 years ago, maybe I could have chosen a different operator for list concatenation. But I don't think the issue is important enough to fix, even if we ever did a Python 4.)<br><br>--Guido<br>

<br><div class="gmail_quote">On Fri, Dec 30, 2011 at 9:40 AM, Guido van Rossum <span dir="ltr"><<a href="mailto:guido@python.org">guido@python.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

Hi Julien,<br><br>Don't despair! I have tried to get people to warm up to dict addition too -- in fact it was my counter-proposal at the time when we were considering adding sets to the language. I will look at your proposal, but I have a point of order first: this should be discussed on python-ideas, not on python-dev. I have added python-ideas to the thread and moved python-dev to Bcc, so followups will hopefully all go to python-ideas.<br>


<br>--Guido<div class="HOEnZb"><div class="h5"><br><br><div class="gmail_quote">On Fri, Dec 30, 2011 at 7:26 AM, julien tayon <span dir="ltr"><<a href="mailto:julien@tayon.net" target="_blank">julien@tayon.net</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hello,<br>
Sorry to annoy the very busy core devs :) out of the blue<br>
<br>
I quite noticed people were<br>
1) wanting to have a new dict for Xmas<br>
2) strongly resenting dict addition.<br>
<br>
Even though I am not a good developper, I have come to a definition of<br>
addition that would follow algebraic rules, and not something of a<br>
dutch logic. (it is a jest, not a troll)<br>
<br>
I propose the following code to validate my point of view regarding<br>
the dictionnatry addition as a proof of concept :<br>
<a href="https://github.com/jul/ADictAdd_iction/blob/master/test.py" target="_blank">https://github.com/jul/ADictAdd_iction/blob/master/test.py</a><br>
<br>
It follows all my dusty math books regarding addition + it has the<br>
amability to have rules of conservation.<br>
<br>
I pretty much see a real advantage in this behaviour in functional<br>
programming (map/reduce). (see the demonstrate.py), and it has a sense<br>
(if dict can be seen has vectors).<br>
<br>
I have been told to be a troll, but I am pretty serious.<br>
<br>
Since, I coded with luck, no internet, intuition, and a complete<br>
ignorance of the real meaning of the magic methods most of the time,<br>
thus the actual implementation of the addition surely needs a complete<br>
refactoring.<br>
<br>
Sheers,<br>
Bonne fêtes<br>
Julien<br>
_______________________________________________<br>
Python-Dev mailing list<br>
<a href="mailto:Python-Dev@python.org" target="_blank">Python-Dev@python.org</a><br>
<a href="http://mail.python.org/mailman/listinfo/python-dev" target="_blank">http://mail.python.org/mailman/listinfo/python-dev</a><br>
Unsubscribe: <a href="http://mail.python.org/mailman/options/python-dev/guido%40python.org" target="_blank">http://mail.python.org/mailman/options/python-dev/guido%40python.org</a><br>
</blockquote></div><br><br clear="all"><br></div></div><span class="HOEnZb"><font color="#888888">-- <br>--Guido van Rossum (<a href="http://python.org/%7Eguido" target="_blank">python.org/~guido</a>)<br>
</font></span></blockquote></div><br><br clear="all"><br>-- <br>--Guido van Rossum (<a href="http://python.org/~guido">python.org/~guido</a>)<br>