[Python-Dev] Trinary Operators
Gary Herron
gherron@islandtraining.com
Thu, 6 Feb 2003 10:39:52 -0800
On Thursday 06 February 2003 10:08 am, Guido van Rossum wrote:
> > Guido> I think I've seen the suggestion
> >
> > Guido> x = (y if y>z else z)
> >
> > Guido> :-)
> >
> > That's not bad, even though it looks Perlish :-)
> >
> > It has the advantage of looking like a list comprehension.
> >
> > I presume the parentheses would be mandatory.
>
> Maybe I should write a PEP and let the folks in c.l.py vote on it,
> just for fun. (I expect to get about as many yes votes as no votes. :-)
>
If this is just for fun, why stop with just "trinary"? How about one
of the following (depending on ease of parsing)? These look even more
like list comprehension.
x = (e1 if c1 e2 if c2 e3 if c3 ... else d)
x = (e1 if c1 else e2 if c2 else e3 if c3 ... else d)
I guess we'd have to call it the n-ary operator.
Gary Herron