On 2018-02-23 12:44, Neil Girdhar wrote:
On Fri, Feb 23, 2018 at 12:35 PM Kyle Lahnakoski
mailto:klahnakoski@mozilla.com> wrote: > [ > (w, w**2) > for x in (1, 2, 3, 4) > let y = x+1 > for a in range(y) > let z = a+1 > if z > 2 > for b in range(z) > let w = z+1 > ]
which is a short form for:
> def stuff(): > for x in (1, 2, 3, 4): > y = x+1 > for a in range(y): > z = a+1 > if z > 2: > for b in range(z): > w = z+1 > yield (w, w**2) > > list(stuff())
Is it that much shorter that it's worth giving up the benefit of indentation?
Saving the indentation? Oh yes, for sure! This code reads like a story, the indentation is superfluous to that story. Should we add it to Python? I don't know; I quick scan through my own code, and I do not see much opportunity for list comprehensions of this complexity. Either my data structures are not that complicated, or I have try/except blocks inside a loop, or I am using a real query language (like SQL). pythonql seems to solve all these problems well enough (https://github.com/pythonql/pythonql).