Conditional operator in Python?
Marcin 'Qrczak' Kowalczyk
qrczak at knm.org.pl
Sun Apr 1 08:12:58 EDT 2001
Sat, 31 Mar 2001 21:22:54 -0800, Erik Max Francis <max at alcyone.com> pisze:
> The Python FAQ, for instance, suggests x ? a : b can be reliably
> substituted with
>
> (x and [a] or [b])[0]
It computes both a and b. A correct solution is
(0 and (lambda: a) or (lambda: b))()
Yes, it is ugly.
--
__("< Marcin Kowalczyk * qrczak at knm.org.pl http://qrczak.ids.net.pl/
\__/
^^ SYGNATURA ZASTĘPCZA
QRCZAK
More information about the Python-list
mailing list