[Python-ideas] Accessing the result of comprehension's expression from the conditional

Jason Orendorff jason.orendorff at gmail.com
Fri Jun 19 16:17:53 CEST 2009


On Fri, Jun 19, 2009 at 2:39 AM, Lie Ryan<lie.1296 at gmail.com> wrote:
> res = [x**x as F for x in nums if F < 100]

In some languages, you can use "let" in a list comprehension:

  [f | x <- nums, let f = x**x, f < 100]

which I guess might look something like this in python:

  [f for x in nums let f = x**x if f < 100]

(JavaScript actually has a `let` keyword so I suspect we will
eventually adopt something like that.)

-j



More information about the Python-ideas mailing list