Idiosyncratic python

Todd toddrjen at gmail.com
Thu Sep 24 12:54:03 EDT 2015


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.python at 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20150924/8dd967c0/attachment.html>


More information about the Python-list mailing list