PEP 308: A PEP Writer's Experience - PRO

Andrew Koenig ark at
Mon Feb 10 03:40:47 CET 2003

Paul> Andrew Koenig <ark at> writes:

Samuele> ife = lambda box: box[0]
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
evaluating [x].

Andrew Koenig, ark at,

More information about the Python-list mailing list