Conditional operator in Python?
Weet.Vanniks at el_simpatico.be
Tue Sep 4 09:09:38 CEST 2001
What about :
This seems much cleaner to me than all those contorsions with the syntax.
thp at cs.ucr.edu wrote:
> Marcin 'Qrczak' Kowalczyk <qrczak at knm.org.pl> wrote:
> : 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])
> : It computes both a and b.
> : A correct solution is
> : (0 and (lambda: a) or (lambda: b))()
> : Yes, it is ugly.
> Agreed. Something more aesthetic is definitely needed. I hate writing:
> factorial = lambda x : (x<=1 and  or [x*factorial(x-1)])
> Tom Payne
More information about the Python-list