for statement list comprehension-like extention proposal
newsgroups at jhrothjr.com
Wed Aug 20 02:46:15 CEST 2003
"Ryan Lowe" <ryanlowe0 at msn.com> wrote in message
news:zjz0b.126468$_R5.47127053 at news4.srv.hcvlny.cv.net...
> i thought id ask here before wirting a PEP, if people thought it would be
> good enhancement to allow if clauses in regular for-statements like so:
> >>> for x in y if x < 10 :
> is semantically equivalent to
> >>> for x in [x for x in y if x < 10] :
> but is shorter and easier to read. basically, the if works as a filter for
> the values in the iterator. its not a major change, purely syntactic
> and clearly backwards-compatible.
> seem reasonable?
It doesn't do anything for me. I actually find it harder to
read: the brackets at least guide my eyes to the various parts
of the line, which the form you propose doesn't do.
Also, its most definitely
not backwards compatible, and I wish you wouldn't
send three duplicate messages to the newsgroup with
different headers but the same body.
More information about the Python-list