[Python-ideas] Generator syntax hooks?
Steven D'Aprano
steve at pearwood.info
Fri Aug 11 01:18:34 EDT 2017
On Fri, Aug 11, 2017 at 02:49:10PM +1000, Steven D'Aprano wrote:
> On Thu, Aug 10, 2017 at 01:25:24PM -0700, Chris Barker wrote:
> > I guess I think of it like this:
> >
> > "if" is providing a filtering mechanism
> >
> > "while" is providing a termination mechanism
> >
> > -- is there a use case anyone can think of when they would want the while
> > to be applied to the list AFTER filtering?
Oops, sorry I had a thinko and read your question in the opposite sense
than it actually is. See my response to Nick for an example:
I have an iterable of arbitrary objects. I want to ignore anything that
isn't a string, and halt if the string doesn't start with "A".
[expr for s in objects if isinstance(s, str) while s.startswith("A")]
--
Steve
More information about the Python-ideas
mailing list