[Python-ideas] if-statement in for-loop
Random832
random832 at fastmail.com
Tue Oct 4 09:20:02 EDT 2016
On Tue, Oct 4, 2016, at 07:37, Nick Coghlan wrote:
> And when you add the "else" clause that's supported by both "for" and
> "if", what does that mean in the abbreviated form?
>
> for item in items if item is not None:
> ...
> else:
> # ???
>
> Or is the implicit proposal that this form be special cased to
> disallow the "else" clause?
I think it's obvious that it would be on the outermost construct (i.e.
the one that would still be at the same indentation level fully
expanded).
The *real* question is what "break" should do. I think it should
likewise break from the outermost for-loop (but "continue" should still
continue the innermost one), but this does mean that it's not
mechanically identical to the "equivalent" nested loops [it would,
however, make it mechanically identical to the "generator and single
loop" form]
More information about the Python-ideas
mailing list