Path: csiph.com!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Jussi Piitulainen Newsgroups: comp.lang.python Subject: Re: The Cost of Dynamism (was Re: Pyhon 2.x or 3.x, which is faster?) Date: Tue, 22 Mar 2016 15:15:09 +0200 Organization: A noiseless patient Spider Lines: 23 Message-ID: References: <56e44258$0$1598$c3e8da3$5496439d@news.astraweb.com> <8737rvxs89.fsf@elektro.pacujo.net> <56e7483d$0$1608$c3e8da3$5496439d@news.astraweb.com> <56f09973$0$1601$c3e8da3$5496439d@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="305c68510616a2e7ac08bcd2ff1598bd"; logging-data="2771"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19ms+oljd5x8HCfrLngP9r7Chbi442NXc4=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:qmG8ppHXrL2Pma5RJH/tNfwks/k= sha1:4yqg2SxIPhHBIE5aAEqVsQMBEvE= Xref: csiph.com comp.lang.python:105480 Chris Angelico writes: > On Tue, Mar 22, 2016 at 11:52 PM, Jussi Piitulainen wrote: >> Now you can ask for the next item that satisfies a condition using a >> generator expression: >> >> next(symbol for symbol in stream if not symbol.isspace()) >> ---> '/' >> >> next(symbol for symbol in stream if not symbol.isspace()) >> ---> '*' > > Or use filter(), which is sometimes clearer: > > # You probably want a more sophisticated function here > def nonspace(ch): return not ch.isspace() > > next(filter(nonspace, stream)) Sure. # But there's more fun hiding in the standard library. next(itertools.filterfalse(operator.methodcaller('isspace'), stream))