On Sep 24, 2015 18:59, "Chris Angelico" <ros...@gmail.com> wrote:
>
> 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.
True, but the code I saw doing this was just choosing between simple float
literals.
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to