[Python-Dev] Adding C ternary select (a?b:c) to Python?

Christian Tismer tismer@tismer.com
Mon, 31 Jan 2000 12:46:50 +0100


Ka-Ping Yee wrote:
> 
> On Sun, 30 Jan 2000, Tim Peters wrote:
> > If this goes in (I'm not deadly opposed, just more opposed than in favor),
> > I'd like to see "else" used instead of the colon (cond "?" true "else"
> > false).  The question mark is reasonably mnemonic, but a colon makes no
> > sense here.
> 
> I agree with that sentiment (along the lines of the philosophy that
> chose "and" over "&&"), and it seems to me that it makes the most sense
> to use words for both:
> 
>     a = x > 0 then x else -x

I would favorise this as well instead of using ?: .
Maybe it would make sense to be even more verbose and use an "if"
as well?

       a = if x > 0 then x else -x

       sign = lambda x: if x > 0 then 1 elif x then -1 else 0

ciao - chris

-- 
Christian Tismer             :^)   <mailto:tismer@appliedbiometrics.com>
Applied Biometrics GmbH      :     Have a break! Take a ride on Python's
Düppelstr. 31                :    *Starship* http://starship.python.net
12163 Berlin                 :     PGP key -> http://wwwkeys.pgp.net
PGP Fingerprint       E182 71C7 1A9D 66E9 9D15  D3CC D4D7 93E2 1FAE F6DF
     we're tired of banana software - shipped green, ripens at home