Conditional operator in Python?
Michael Abbott
michael at rcp.co.uk
Tue Sep 4 04:39:29 EDT 2001
Marcin 'Qrczak' Kowalczyk <qrczak at knm.org.pl> wrote in
news:slrn9p942t.fg.qrczak at qrnik.zagroda:
> Tue, 4 Sep 2001 07:24:13 +0000 (UTC), thp at cs.ucr.edu <thp at cs.ucr.edu>
> pisze:
>
> IMHO this would look more clearly:
>
> p = lambda k, n:
> if k < 1 or k > n then 0 else
> if n == 1 or n == k then 1 else
> p( k-1, n-1 ) + p (k, n-k )
>
I think (though it would need a bit of careful checking) that there is no
conflict with the existing Python syntax in making
if <expr> then <expr> else <expr>
an expression.
Perhaps adding this to the syntax could be a PEP? Obviously the semantics
of the expression
if a then b else c
could be explained as equal to the expression
((a and [b]) or [c])[0]
More information about the Python-list
mailing list