the PHP ternary operator equivalent on Python

Fredrik Lundh fredrik at
Wed Nov 23 23:30:13 CET 2005

Paul Rubin wrote:

> It gets messy for a more complicated structure:
>    d = {'x': x1() if x_is_old else x2(),
>         'y': y1() if y_is_old else y2(),
>         'z': z1() if z_is_old else z2() }
> etc.

somewhere between the '}' and the '.', a data-driven approach will
be more readable, easier to maintain, and nearly as efficient.

(and with an example as regular as yours, the data table can be auto-


More information about the Python-list mailing list