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

Sven R. Kunze srkunze at mail.de
Sun Sep 11 16:20:35 EDT 2016


On 11.09.2016 22:15, C Anthony Risinger wrote:
>
> On Sep 11, 2016 7:11 AM, "Chris Angelico" <rosuav at gmail.com 
> <mailto: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.
>

Same here.

Most of the time it's just a single condition which disturbs the 
coherence of the loop body.

> 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).
>
>
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20160911/4a9d5508/attachment-0001.html>


More information about the Python-ideas mailing list