Ternery operator
Erik Max Francis
max at alcyone.com
Tue Sep 9 15:21:05 EDT 2003
Michael Chermside wrote:
> Uwe Schmitt writes:
>
> > Normaly[sic] you should simulate "C ? T : F"
> >
> > either by
> > [T,F][not C]
> >
> > or
> >
> > (C and [T] or [F])[0]
> > ...
>
> NOT TRUE!
>
> NEITHER of your options does short-circuit evaluation.
The latter does, due to its use of and/or. An equivalent form including
lambdas is
(C and lambda: T or lambda: F)()
--
Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/
__ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE
/ \ Silence is the most perfect expression of scorn.
\__/ George Bernard Shaw
More information about the Python-list
mailing list