Equivalent to (a ? b : c) ?

Jesper Hertel jh at cddk.dk
Mon Dec 20 12:08:18 EST 1999


I hope this was a joke. That kind of constructions is impossible to read for
other programmers, making the program hard to maintain.

I like maxm's function much better, because you can easily understand what
the meaning is.


Jesper Hertel


Alex Martelli <Alex.Martelli at think3.com> wrote in message
news:6D8A17398E28D3119F860090274DD7DB4B3D62 at pces.cadlab.it...
> Scott Malraux writes:
>
> > I remember seeing the Python equivalent to C's (a?b:c) inline if
> > statement, but I can't find it for the life of me... can some kind soul
> > jog my memory for me please?
> >
> For the general case I think it was:
>
> ((a and (b,)) or (c,))[0]
>
> where the tuple trickery is just in case b is false; if you
> know b can't be false,
>
> (a and b) or c
>
> seems more readable.  I think the parentheses can also
> be dispensed with, but I'm not conversant enough with
> the precedence to dare do that:-).
>
>
> Alex
>
>





More information about the Python-list mailing list