For review: PEP 308 - If-then-else expression

Paul Rubin phr-n2003b at NOSPAMnightsong.com
Sat Feb 8 00:23:14 EST 2003


Andrew Koenig <ark at research.att.com> writes:
> Paul> y = [sqrt(z) if z > 0.0 else 0.0 for z in x]
> 
> Paul> I don't remember the precedence of the 'for' here. It would be
> Paul> good if this is correct.
> 
> Indeed.
> 
> And while we're at it:
> 
>         y = map(lambda z: sqrt(z) if z > 0.0 else 0.0, x)

That particular example can be taken care of with

   y = [sqrt(max(z, 0.0)) for z in x]

but I agree with the motivation.




More information about the Python-list mailing list