Equivalent to (a ? b : c) ?

Tim Peters tim_one at email.msn.com
Thu Dec 30 01:09:25 EST 1999


[Rob Hodges, about

    (a and [b] or [c])[0]

and friends]

> ...
> which I guess is what idiomatic means -- an idiocy so common that
> recognising it quickly becomes automatic.  (Thereby making it seem
> less of an idiocy.)

Na, this isn't idiomatic Python.  I blessed <ahem> the Python world with
this construct in the early 90's (see FAQ 4.16), in a light-hearted thread
that just wondered whether it could be *done*.  I've never used it in a real
program, and am not sure I've seen anyone else use it except for playful
obfuscation.

> ...
> Out of curiosity, is there any advantage to using singleton tuples
> rather than lists?  And is there any advantage in using the
> seemingly-redundant parens?

There's no advantage in using any flavor of this silliness.

much-less-in-discussing-it<wink>-ly y'rs  - tim






More information about the Python-list mailing list