Single line if statement with a continue

Chris Angelico rosuav at gmail.com
Wed Dec 14 23:35:28 EST 2022


On Thu, 15 Dec 2022 at 14:41, Aaron P <transreductionist at gmail.com> wrote:
>
> I occasionally run across something like:
>
> for idx, thing in enumerate(things):
>     if idx == 103:
>         continue
>     do_something_with(thing)
>
> It seems more succinct and cleaner to use:
>
> if idx == 103: continue.
>
> Of course this would be considered an anti-pattern, and Flake8 will complain.
>
> Any opinions, or feedback on the matter.

Nothing at all wrong with writing that on a single line. If you have
issues with Flake8 not accepting your choices, reconfigure Flake8 :)

ChrisA


More information about the Python-list mailing list