(test) ? a:b

Ian Kelly ian.g.kelly at gmail.com
Sat Oct 25 15:53:37 CEST 2014

On Sat, Oct 25, 2014 at 5:58 AM, Ned Batchelder <ned at nedbatchelder.com> wrote:
> You mention "standard Python idioms."  I think this style of
> conditional-via-indexing is becoming quite uncommon, and is no longer one of
> the standard Python idioms.  This is now in the category of "outdated hack."

I think that's probably true. And even in code written for versions of
Python than predate the ternary, I think I've seen the idiom "(cond
and [if_true] or [if_false])[0]" more often than the one being
discussed -- perhaps because it more closely resembles the format of
the C ternary

More information about the Python-list mailing list