<div dir="auto"><span style="font-family:sans-serif">This idea was mentioned (by me) at a time yes, but wasn't written in the document. </span><div dir="auto"><span style="font-family:sans-serif"><br></span></div><div dir="auto"><span style="font-family:sans-serif">I think one of the thing was that it would make the grammar non LL1 because when seeing the token "for" in a list comprehension it wouldn't know in advance if it's the loop or the assignment.</span></div><div dir="auto"><span style="font-family:sans-serif"><br></span></div><div dir="auto"><span style="font-family:sans-serif">And also, it might confuse people because 'for' is for iteration.</span></div><div dir="auto"><span style="font-family:sans-serif"><br></span></div><div dir="auto"><span style="font-family:sans-serif"><br></span></div></div><br><div class="gmail_quote"><div dir="ltr">Le jeu. 24 mai 2018 à 17:54, Alexander Belopolsky <<a href="mailto:alexander.belopolsky@gmail.com">alexander.belopolsky@gmail.com</a>> a écrit :<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">I have read most of the PEP 572 related threads, but I don't think I've seen this idea.  As many other people mentioned, Python already allows a trick to introduce local bindings in generator expressions and list comprehensions.  This can be achieved by adding a "for var in [<expr>]" clause.  I propose to make "for var = <expr>" have the same effect as "for var in [<expr>]".<div><br></div><div>Note that in the case of filters, the order will be different from that in the original "given" proposal: instead of </div><div><br></div><div>[(x, y, x/y) for x in data if y <span class="m_3918822352320729859gmail-il">given</span> y = f(x)]<br></div><div><br></div><div>we will write</div><div><br></div><div>[(x, y, x/y) for x in data for y = f(x) if y]<br></div><div><br></div><div>The use of "for" in place of "given" in the if statements does not look too bad:</div><div><br></div><div>   if m for m = pattern.search(data):<br>        ...<br><div><div>    elif m for m = other_pattern.search(data)):<br>        ...<br></div><div>    else:<br>        ...</div></div></div><div><br></div><div>I have to admit that </div><div><br></div><div>while m <span class="m_3918822352320729859gmail-il">for</span> m = pattern.search(remaining_data):<br>        ...<br></div><div><br></div><div>looks strange at first because both while and for are strongly associated with loops, but if you read "for var = <expr>" as "for var equals expression", the difference between that and "for var in (iterable) expression" becomes apparent.</div></div>
_______________________________________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org" target="_blank" rel="noreferrer">Python-ideas@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-ideas" rel="noreferrer noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/python-ideas</a><br>
Code of Conduct: <a href="http://python.org/psf/codeofconduct/" rel="noreferrer noreferrer" target="_blank">http://python.org/psf/codeofconduct/</a><br>
</blockquote></div>