On Tue, Mar 1, 2022 at 6:43 PM Steven D'Aprano <[email protected]> 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:
> some_op(x)
>
I think it's really the equivalent of
for x in y:
if not x in c:
break
do_stuff
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):
side_effect(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 ;-)
-CHB
--
Christopher Barker, PhD (Chris)
Python Language Consulting
- Teaching
- Scientific Software Development
- Desktop GUI and Web Development
- wxPython, numpy, scipy, Cython
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/RIAZUNGF3R3KBWGFOR5G6M3BXB4AW4AX/
Code of Conduct: http://python.org/psf/codeofconduct/