PEP 308: A PEP Writer's Experience - PRO
ark at research.att.com
Mon Feb 10 03:40:47 CET 2003
Paul> Andrew Koenig <ark at research.att.com> writes:
Samuele> ife = lambda box: box
Samuele> z = ife(cond and [x] or [y])
Samuele> if Python had had a ternary cond op, I would never have seen
Samuele> that <sniff>.
>> You're right -- that's about the nicest workaround I've seen.
Paul> I'm missing something--x and y both get evaluated in that example,
Paul> so it's only a partial work around?
How so? If cond is true, then (cond and [x]) is true, so [y] is not
evaluated. If cond is false, then (cond and [x]) is false without
Andrew Koenig, ark at research.att.com, http://www.research.att.com/info/ark
More information about the Python-list