
Feb. 26, 2010
12:40 a.m.
spir wrote:
But the analog does not apply to filter-only list comps: [x in numbers if x%2==1] # SyntaxError
If you were allowed to say that, you should also be able to say [x in numbers] but this already has a meaning as an ordinary list constructor. Requiring the word 'for' to appear in an LC ensures that there is never any ambiguity. However, it might be possible to phrase it another way, e.g. [x from numbers if x%2==1] -- Greg