Re:A few things to remember while coding in Python
by swdunlop on Saturday May 19, 2012 @05:23PM
(#3997111)
Python offers filtering expressions in its generator syntax. I find Python's "lambda" hurts readability for most uses, which pains me as a Lisp geek. Your example, as a generator:
The parens aren't necessary, but they help readability for people who aren't used to the generator order of operations. (Again, Lisp geek, more parens means more readable in my fractured mind.)
[ Parent
| on HN ]
Re:A few things to remember while coding in Python
by dmg8 on Saturday May 19, 2012 @05:51PM
(#3997192)
The parens are required. What you've written raises a SyntaxError.
You can omit them in the generator expression if it's being passed directly as the only parameter to a function:
halve_evens_only = list(i/2 for i in nums if i % 2 != 0)