(test) ? a:b

Marko Rauhamaa marko at pacujo.net
Fri Oct 24 05:37:33 EDT 2014


Steven D'Aprano <steve+comp.lang.python at pearwood.info>:

> So why is it hard to read when the index is a flag?
>
> value = [f, g][cond]()

So, subjectively, which syntax would you prefer:

    if j < 10:
        j += 1
    else:
        j = 3

or:

    j = j + 1 if j < 10 else 3

or:

    j = (lambda: 3, lambda: j + 1)[j < 10]()


Marko



More information about the Python-list mailing list