A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://mail.python.org/pipermail/python-dev/attachments/20180223/1af3090c/attachment.html below:

<div dir="ltr"><div><div><div><div><div><div><div><div>As to the validity or legality of this code, it's both, and working as intended.<br><br></div>A list comprehension of the form<br><br></div>    [STUFF for VAR1 in SEQ1 for VAR2 in SEQ2 for VAR3 in SEQ3]<br><br></div>should be seen (informally) as<br><br></div>    for VAR1 in SEQ1:<br></div>        for VAR2 in SEQ2:<br></div>            for VAR3 in SEQ3:<br></div>                "put STUFF in the result"<br><br></div>(If there are `if COND` phrases too those get inserted into the nested set of blocks where they occur in the sequence.)<br><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Feb 23, 2018 at 9:41 AM, Chris Barker - NOAA Federal <span dir="ltr"><<a href="mailto:chris.barker@noaa.gov" target="_blank">chris.barker@noaa.gov</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">> Is it similar enough to<br>
><br>
>  Â  def f(x=[0]):<br>
<br>
</span>No, not at all â€” it’s a very different use case.<br>
<br>
When I first saw this on the original thread, I needed to stare at it<br>
a good while, and then whip up some code to experiment with it to know<br>
what it did.<br>
<br>
And not because I don’t know what a single element list means, or what<br>
it means to iterate over a single element list, or what two fors mean<br>
in a comprehension.<br>
<br>
I was confused by the â€˜x’ in the second iterable. I guess I’m (still)<br>
not really clear on the scope(s) inside a comprehension, and when the<br>
elements get evaluated in a list.<br>
<br>
I expected that the list would be created once, with the value x had<br>
initially, rather than getting the-evaluated each time through the<br>
outer loop.<br>
<br>
So I think that it is a very confusing use of comprehensions, and<br>
always will be. I’m still surprised it’s legal. Anyone know if this<br>
being allowed was deliberate or just kind of fell out of the<br>
implementation?<br>
<br>
So no, I don’t think it should be promoted as idiomatic.<br>
<br>
All that being said, it’s valid Python, so why not optimize it?<br>
<br>
-CHB<br>
<div class="HOEnZb"><div class="h5">______________________________<wbr>_________________<br>
Python-Dev mailing list<br>
<a href="mailto:Python-Dev@python.org">Python-Dev@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-dev" rel="noreferrer" target="_blank">https://mail.python.org/<wbr>mailman/listinfo/python-dev</a><br>
Unsubscribe: <a href="https://mail.python.org/mailman/options/python-dev/guido%40python.org" rel="noreferrer" target="_blank">https://mail.python.org/<wbr>mailman/options/python-dev/<wbr>guido%40python.org</a><br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br><div class="gmail_signature" data-smartmail="gmail_signature">--Guido van Rossum (<a href="http://python.org/~guido" target="_blank">python.org/~guido</a>)</div>
</div>

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4