<div dir="ltr"><br><br><div class="gmail_quote"><div dir="ltr">On Fri, Feb 23, 2018 at 12:35 PM Kyle Lahnakoski <<a href="mailto:klahnakoski@mozilla.com">klahnakoski@mozilla.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I believe list comprehensions are difficult to read because they are not<br>
formatted properly. For me, list comprehension clauses are an<br>
expression, followed by clauses executed in the order. Any list<br>
comprehension with more than one clause should be one-line-per clause.<br>
<br>
Examples inline:<br>
<br>
On 2018-02-15 19:57, Steven D'Aprano wrote:<br>
> Where should the assignment go? [(y, y**2) let y = x+1 for x in (1, 2,<br>
> 3, 4)] [(y, y**2) for x in (1, 2, 3, 4) let y = x+1]<br>
<br>
Since y is a function of x, it must follow the for clause:<br>
<br>
> [<br>
> (y, y ** 2)<br>
> for x in (1, 2, 3, 4)<br>
> let y = x + 1<br>
> ]<br>
<br>
> How do they interact when you have multiple loops and if-clauses? [(w,<br>
> w**2) for x in (1, 2, 3, 4) let y = x+1 for a in range(y) let z = a+1<br>
> if z > 2 for b in range(z) let w = z+1]<br>
<br>
They are applied in order:<br>
<br>
> [<br>
> (w, w**2)<br>
> for x in (1, 2, 3, 4)<br>
> let y = x+1<br>
> for a in range(y)<br>
> let z = a+1<br>
> if z > 2<br>
> for b in range(z)<br>
> let w = z+1<br>
> ]<br>
<br>
which is a short form for:<br>
<br>
> def stuff():<br>
> for x in (1, 2, 3, 4):<br>
> y = x+1<br>
> for a in range(y):<br>
> z = a+1<br>
> if z > 2:<br>
> for b in range(z):<br>
> w = z+1<br>
> yield (w, w**2)<br>
><br>
> list(stuff())<br></blockquote><div><br></div><div>Is it that much shorter that it's worth giving up the benefit of indentation? </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
<br>
_______________________________________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org" target="_blank">Python-ideas@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-ideas" rel="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" target="_blank">http://python.org/psf/codeofconduct/</a><br>
<br>
--<br>
<br>
---<br>
You received this message because you are subscribed to a topic in the Google Groups "python-ideas" group.<br>
To unsubscribe from this topic, visit <a href="https://groups.google.com/d/topic/python-ideas/KwZtO4rpAGE/unsubscribe" rel="noreferrer" target="_blank">https://groups.google.com/d/topic/python-ideas/KwZtO4rpAGE/unsubscribe</a>.<br>
To unsubscribe from this group and all its topics, send an email to <a href="mailto:python-ideas%2Bunsubscribe@googlegroups.com" target="_blank">python-ideas+unsubscribe@googlegroups.com</a>.<br>
For more options, visit <a href="https://groups.google.com/d/optout" rel="noreferrer" target="_blank">https://groups.google.com/d/optout</a>.<br>
</blockquote></div></div>