[Python-ideas] if-statement in for-loop

C Anthony Risinger anthony at xtfx.me
Sun Sep 11 16:15:41 EDT 2016


On Sep 11, 2016 7:11 AM, "Chris Angelico" <rosuav at gmail.com> wrote:
>
> That said, though, filtered iteration isn't common enough to demand
> its own syntax IMO. I do it fairly often,

I do it often enough to want this. When I first started writing Python this
struck me as an inconsistency... if it's useful in comprehensions, why not
regular loops? I realize comprehensions are all about construction of the
list itself, but the parallel still exists.

Also feels similar to guard statements. I'd love to see Python gain more
pattern matching and destructuring features because they are wonderful in
Erlang/Elixir.

> but it's usually fine to
> just have a condition on a separate line. (I do use ": continue"
> rather than making it two lines.)

FWIW, code I write or review would mandate this be two lines followed by a
blank line, so 3 total. I require any abrupt change or termination in the
current flow of control to be followed by a blank line so the reader
clearly sees the possible jump (continue, break, and return especially).
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20160911/78c67017/attachment.html>


More information about the Python-ideas mailing list