Conditional operator in Python?
Marcin 'Qrczak' Kowalczyk
qrczak at knm.org.pl
Tue Sep 4 04:27:09 EDT 2001
Tue, 4 Sep 2001 07:24:13 +0000 (UTC), thp at cs.ucr.edu <thp at cs.ucr.edu> pisze:
> Using, say, ?: notation this would be written:
>
> p = lambda k, n :
> k < 1 or k > n ? 0 :
> n == 1 or n == k ? 1 :
> p( k-1, n-1 ) + p (k, n-k )
>
> which seems much more concise and readable.
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 )
--
__("< Marcin Kowalczyk * qrczak at knm.org.pl http://qrczak.ids.net.pl/
\__/
^^ SYGNATURA ZASTĘPCZA
QRCZAK
More information about the Python-list
mailing list