-1. Extra complexity for no benefit. Attractive nuisance to making overly complex statement lines. On Tue, Mar 1, 2022, 8:31 PM Svein Seldal <sveinse@seldal.com> wrote:
I'm sorry for reposting, but this message got stuck in moderation approval for 5 days so I figured I should try again.
I'd like to propose extending the for statement to include conditionals akin to comprehensions in order to simplify for loop statements:
`for .. in .. if ..:`
E.g.
for x in y if x in c: some_op(x)
which is functionally equivalent as
for x in y: if x not in c: continue some_op(x)
The `for .. in .. if` syntax is a well-known construct from list comprehension syntax [1]. Other alternative ways to do this with list comprehension is:
for x in (a for a in y if c):
or
it = (a for a in y if c) for x in it:
Without having examined all use cases, I believe the same syntax should be applied this syntax as for asynchronous comprehensions.
[1] PEP 202 - List Comprehensions [2] PEP 530 - Asynchronous Comprehensions
Best regards, Svein Seldal _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-leave@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/7IXPRO... Code of Conduct: http://python.org/psf/codeofconduct/