[Python-Dev] Re: Trinary Operators (original) (raw)

Gerald S. Williams gsw@agere.com
Fri, 7 Feb 2003 14:37:57 -0500


To me, the major problem with the (a and [b] or [c])[0] solution shown in the FAQ is that it's not immediately clear what you are doing. A more likely spelling of that solution is:

def ifelse(result): return result[0] ... x1 = ifelse(a and [x] or [y]) x2 = ifelse(a and [x] or b and [y] or [z]) x3 = ifelse(a and [x] or b and [y] or c and ...)

The q() function solution shown there doesn't extend as nicely and forces you to add "lambda:" if you don't want both alternatives evaluated.

-Jerry