[Python-ideas] Assignments in list/generator expressions
Eugene Toder
eltoder at gmail.com
Sat Apr 9 21:04:07 CEST 2011
> Uh, that's hardly strange considering that Python doesn't have local
> assignments in expressions anywhere.
Well, depending on your definition of "assignments in expression" you
can say that Haskell doesn't have them either.
Or you can say that Python has them since list comprehension was
introduced -- for x in xs is an assignment to x. In fact, I'm reminded
that local assignment in list comprehension is easily emulated with
for:
ys = [y for x in xs for y in [f(x)] if y]
Eugene
More information about the Python-ideas
mailing list