Is there some sort of let
syntax for a variable in the python for
comprehension? What I mean is a way to bind a newly named variable like an iteration, but without actually iterating anything.
data = [w for y in f() let z = g(y) if z > 0 for w in h(z)]
This can be done in Python in a more cryptic way of course by making a singleton list, [g(y)]
, which is what I do, being not a python expert.
data = [w for y in f() for z in [g(y)] if z > 0 for w in h(z)]
The let
syntax exists for the equivalent of for
comprehensions in Common Lisp, Clojure, and Scala, so I wondered whether there is corresponding syntax in Python as well.