[Python-ideas] Assignments in list/generator expressions
Eugene Toder
eltoder at gmail.com
Sat Apr 9 18:27:21 CEST 2011
Survey of list comprehension features and syntax:
1) Structure
Haskell: [expr | generators], generators = generator (, generator)*
Python: [expr generators], generators = generator+
2) Take
Haskell: x <- xs
Python: for x in xs
3) Filter
Haskell: cond
Python: if cond
4) Local definition
Haskell: let name = expr
Python: strangely missing
I'd rather add syntax equivalent to Haskell's let, than inventing
completely new syntax. E.g. with name = expr. Original from the first
post becomes
ys = [y for x in xs with y = f(x) if y]
but it's more flexible in general.
Eugene
More information about the Python-ideas
mailing list