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
On Sep 24, 2015 8:06 AM, "Steven D'Aprano" <
steve+comp.lang.pyt...@pearwood.info> wrote:

> I was looking at an in-house code base today, and the author seems to have
> a
> rather idiosyncratic approach to Python. For example:
>
>
> for k, v in mydict.items():
>     del(k)
>     ...
>
>
> instead of the more obvious
>
> for v in mydict.values():
>     ...
>
>
>
> What are your favorite not-wrong-just-weird Python moments?
>
>
>
> --
> Steve
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to