(test) ? a:b

Marko Rauhamaa marko at pacujo.net
Fri Oct 24 20:46:33 CEST 2014


Ian Kelly <ian.g.kelly at gmail.com>:

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

> Yes, the lambda approach falls victim to function calls being slow.

That's just a deficiency in the compiler. There's nothing there that
prevents the optimizer from translating the expression into the
equivalent if statement.

At any rate, the only issue at hand is the obviousness of the idiom. You
should generally choose the syntax that best expresses the logic of the
program.


Marko



More information about the Python-list mailing list