<div dir="ltr">I split off a separate thread on python-ideas [1] specific to the idea of introducing "+" and "+=" operators on a dict.<div><br></div><div>[1] <a href="https://mail.python.org/pipermail/python-ideas/2015-February/031748.html">https://mail.python.org/pipermail/python-ideas/2015-February/031748.html</a></div></div><div class="gmail_extra"><br clear="all"><div><div class="gmail_signature"><br>~ Ian Lee<br></div></div>
<br><div class="gmail_quote">On Tue, Feb 10, 2015 at 10:35 PM, John Wong <span dir="ltr"><<a href="mailto:gokoproject@gmail.com" target="_blank">gokoproject@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote"><span class="">On Wed, Feb 11, 2015 at 12:35 AM, Ian Lee <span dir="ltr"><<a href="mailto:ianlee1521@gmail.com" target="_blank">ianlee1521@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">+1 for adding "+" or "|" operator for merging dicts. To me this operation:<div><br></div><div>>>> {'x': 1, 'y': 2} + {'z': 3}</div><div>{'x': 1, 'y': 2, 'z': 3}</div><div><br></div><div>Is very clear. The only potentially non obvious case I can see then is when there are duplicate keys, in which case the syntax could just be defined that last setter wins, e.g.:<br></div><div><br></div><div>>>> {'x': 1, 'y': 2} + {'x': 3}</div><div>{'x': 3, 'y': 2}<br></div><div><br></div><div>Which is analogous to the example:</div><div><br></div><div><div style="font-size:13px">new_dict = dict1.copy()</div><div style="font-size:13px">new_dict.update(dict2)</div></div></div><div class="gmail_extra"><br clear="all"><div><div><br></div></div></div></blockquote></span><div>Well looking at just list</div><div>a + b yields new list</div><div>a += b yields modified a</div><div>then there is also .extend in list. etc. </div><div><br></div><div>so do we want to follow list's footstep? I like + because + is more natural to read. Maybe this needs to be a separate thread. I am actually amazed to remember dict + dict is not possible... there must be a reason (performance??) for this...</div></div></div></div>
</blockquote></div><br></div>