On Tue, Mar 1, 2022 at 6:43 PM Steven D'Aprano <steve@pearwood.info> wrote:
>     for x in y if x in c:
>         some_op(x)

What does this new syntax give us that we don't already have with this?

    for x in y
        if x in c:

I think it's really the equivalent of

for x in y:
    if not x in c:

which to me give the proposed syntax a bit more relative strength.

I'm probably +0 -- but I do like comprehension syntax, and have often wanted a "side effect" comprehension:
$ side_effect(item) for item in an_iterable if condition(item) $

(using $ 'cause there aren't any more brackets ...)

rather than having to write:

for item in an_iterable:
    if condition(item):

To the point where I sometimes write the list comp and ignore the generated list. NOt too huge a burden to cretae. list of None and throw it away, but it feels wrong ;-)


Christopher Barker, PhD (Chris)

Python Language Consulting
  - Teaching
  - Scientific Software Development
  - Desktop GUI and Web Development
  - wxPython, numpy, scipy, Cython