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

Erik Max Francis max at alcyone.com
Sun Feb 9 02:52:51 EST 2003


Paul Moore wrote:

> y = [sqrt(max(z, 0.0)) for z in x]
> 
> If you think this is a little too obscure, add a comment. I'm assuming
> that you'd object to a suggestion that you define a safe_sqrt()
> function which returns zero for negative numbers...

Why do people keep looking for a magic bullet that will be an expression
that clearly _must_ be expressed with a conditional operator?  Obviously
no such thing exists; anything you can write with a conditional operator
can be rewritten in some other syntax in currently-existing Python.

That's not the point.  The point is whether or not the use of the
conditional operator in those cases is justified and helps readability. 
You may not think that in the sqrt case it is more readable, but it is
at least somewhat readable if you know what a conditional operator is. 
The point is _not_ whether or not such a thing can be recasted in some
other form.

-- 
 Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
 __ San Jose, CA, USA / 37 20 N 121 53 W / &tSftDotIotE
/  \ Always forgive your enemies -- nothing annoys them so much.
\__/ Oscar Wilde
    Bosskey.net: Quake III Arena / http://www.bosskey.net/q3a/
 A personal guide to Quake III Arena.




More information about the Python-list mailing list