Andy Leszczynski wrote:
> How can do elegantly in Python:
>
> if condition:
>     a=1
> else:
>     a=2
>
> like in C:
>
> a=condition?1:2

a=(condition and [1] or [2])[0]

For this simple snippet, I don't think it is better than if/else, But
you can use it in map/reduce or list comprehension/generator expression.

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to