Since there was talk of if-then-else not being allowed in lambda expressions, the following is from "Dive into Python"

Casey Hawthorne caseyhHAMMER_TIME at istar.ca
Thu Jul 20 23:41:29 EDT 2006


Since there was talk of if-then-else not being allowed in lambda
expressions, the following is from "Dive into Python"

The and-or conditional expression trick from page 41 of "Dive into
Python"

Wrap the arguments in lists and then take the first element.

>>> a = ""
>>> b = "second"
>>> (1 and [a] or [b])[0]
''

--
Regards,
Casey



More information about the Python-list mailing list