Proposal: [... for ... while cond(x)]
Eighty
eightyx at gmail.com
Tue Aug 8 16:57:47 EDT 2006
Terry Reedy wrote:
> whereas the analogous expansion of your proposal
>
> for x in xs:
> while cond(x):
> yield e(x)
>
> is an infinite loop and not at all what you mean.
You're right. The syntax is ambiguous. I agree it's not a good idea,
now. :)
> x for x in xs while cond(x) if blah(x)
> x for x in xs if blah(x) while cond(x)
> x*y for x in xs while cond(x) for y in ys
These wouldn't be a problem.
"... for x in xs while cond(x) ..." would be transformed into "... for
x in takewhile(cond, xs) ..."
which could be applied to an if thingy if you first transform
"... for x in xs if cond(x) ..." into "... for x in filter(cond, xs)
...".
More information about the Python-list
mailing list