Possible Duplicate:
Python Ternary Operator
In some languages including Java, C/C++, C#, etc. you can assign a value based on the result of an inline boolean expression.
For example,
return (i < x) ? i : x
This will return i if i < x, otherwise it will return x. I like this because it is much more compact in many cases than the longer syntax which follows.
if (i < x)
return i
else
return x
Is it possible to use this syntax in python and if so, how?
You can use
(x if cond else y), e.g.That will work will lambda function too.