For review: PEP 308 - If-then-else expression
Andrew Koenig
ark at research.att.com
Fri Feb 7 23:55:26 EST 2003
Paul> This did raise the question in my mind about whether or not I
Paul> could just put:
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)
--
Andrew Koenig, ark at research.att.com, http://www.research.att.com/info/ark
More information about the Python-list
mailing list