<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Feb 14, 2015 at 1:09 AM, Stephen J. Turnbull <span dir="ltr"><<a href="mailto:stephen@xemacs.org" target="_blank">stephen@xemacs.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Chris Barker writes:<br>
<br>
> merging two dicts certainly is _something_ like addition.<br>
<br></blockquote><div><br></div><div>So is set union (merging two sets). But in Python, binary + is used mainly for<br><br> - numerical addition (and element-wise numerical addition, in Counter), and<br></div><div> - sequence concatenation.<br><br></div><div>Being unordered, dicts are more like sets than sequences, so the idea of supporting dict1 + dict2 but not set1 + set2 makes me queasy.<br><br></div><div>Cheers,<br>Nathan<br></div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
But you can't say what that something is with precision, even if you<br>
abstract, and nobody contests that different applications of dicts<br>
have naively *different*, and in implementation incompatible,<br>
"somethings".<br>
<br>
So AFAICS you have to fall back on "my editor forces me to type all<br>
the characters, so let's choose the interpretation I use most often<br>
so cI can save some typing without suffering too much cognitive<br>
dissonance."<br>
<br>
Following up the off-topic comment:<br>
<br>
> [In numpy,] we really want readable code:<br>
><br>
> y = a*x**2 + b*x + c<br>
><br>
> really reads well, but it does create a lot of temporaries that kill<br>
> performance for large arrays. You can optimize that by hand by doing<br>
> something like:<br>
><br>
> y = x**2<br>
> y *= a<br>
> y += b*x<br>
> y += c<br>
<br>
Compilers can optimize such things very well, too. I would think that<br>
a generic optimization to the compiled equivalent of<br>
<br>
try:<br>
y = x**2p<br>
y *= a<br>
y += b*x<br>
y += c<br>
except UnimplementedError:<br>
y = a*x**2 + b*x + c<br>
<br>
would be easy to do, possibly controlled by a pragma (I know Guido<br>
doesn't like those, but perhaps an extension PEP 484 "Type Hints"<br>
could help here).<br>
<div class="HOEnZb"><div class="h5"><br>
_______________________________________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org">Python-ideas@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-ideas" target="_blank">https://mail.python.org/mailman/listinfo/python-ideas</a><br>
Code of Conduct: <a href="http://python.org/psf/codeofconduct/" target="_blank">http://python.org/psf/codeofconduct/</a><br>
</div></div></blockquote></div><br></div></div>