PEP 308: A PEP Writer's Experience - PRO

Andrew Koenig ark at research.att.com
Sun Feb 9 21:40:47 EST 2003


Paul> Andrew Koenig <ark at research.att.com> 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 research.att.com, http://www.research.att.com/info/ark




More information about the Python-list mailing list