On Fri, Sep 25, 2015 at 2:54 AM, Todd <toddr...@gmail.com> wrote:
> Using list indexing with booleans in place of a ternary operator.
>
> a = False
> b = [var2, var1][a]
>
> Instead of:
>
> b = var1 if a else var2

Be careful - these are not semantically identical. The first one
evaluates both var1 and var2, while the second will evaluate only the
one it needs. This might be significant if they're not simple names.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to