for statement list comprehension-like extention proposal
Andrew Koenig
ark at acm.org
Wed Aug 20 07:18:53 EDT 2003
Ryan> i thought id ask here before wirting a PEP, if people thought it
Ryan> would be a good enhancement to allow if clauses in regular
Ryan> for-statements like so:
>>>> for x in y if x < 10 :
Ryan> is semantically equivalent to
>>>> for x in [x for x in y if x < 10] :
Ryan> but is shorter and easier to read. basically, the if works as a
Ryan> filter for the values in the iterator. its not a major change,
Ryan> purely syntactic sugar. and clearly backwards-compatible.
Ryan> seem reasonable?
Dunno -- is it really better than writing
for x in y:
if x < 10:
as is already possible? If you could write it in one line, would
you ever do so?
--
Andrew Koenig, ark at acm.org
More information about the Python-list
mailing list