Path: csiph.com!news.mixmin.net!newsreader4.netcologne.de!news.netcologne.de!newsfeed.kamp.net!newsfeed.kamp.net!fu-berlin.de!uni-berlin.de!not-for-mail From: Chris Angelico Newsgroups: comp.lang.python Subject: Re: The Cost of Dynamism (was Re: Pyhon 2.x or 3.x, which is faster?) Date: Wed, 23 Mar 2016 00:24:20 +1100 Lines: 37 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=UTF-8 X-Trace: news.uni-berlin.de 3mTZWrOTeft0i+hucFCyBQpd5Nb4gmTB12TuKJ9U3nlg== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.004 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'cc:addr:python-list': 0.09; '22,': 0.09; 'expression:': 0.09; 'hiding': 0.09; 'subject:which': 0.09; 'def': 0.13; 'wed,': 0.15; "'*'": 0.16; "'/'": 0.16; '2016': 0.16; '23,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'negates': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'subject:?)': 0.16; 'sure.': 0.16; 'write,': 0.16; 'wrote:': 0.16; '>>>': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'filtering': 0.22; 'skip:n 60': 0.22; 'am,': 0.23; 'header:In-Reply-To:1': 0.24; 'chris': 0.26; 'message-id:@mail.gmail.com': 0.27; 'function': 0.28; 'probably': 0.31; 'point,': 0.33; 'stream': 0.33; 'symbol': 0.33; 'tue,': 0.34; 'received:google.com': 0.35; 'next': 0.35; 'could': 0.35; 'ahead': 0.35; 'library.': 0.35; 'item': 0.35; 'sometimes': 0.35; 'but': 0.36; 'received:209.85': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'say': 0.37; 'received:209': 0.38; 'does': 0.39; 'subject:The': 0.61; 'skip:n 10': 0.62; 'more': 0.63; 'mar': 0.65; 'here': 0.66; 'course.': 0.67; '--->': 0.84; 'chrisa': 0.84; 'to:none': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc; bh=GnR0dKMrZeyAkpIU2Q3Wto3eCDNEauIjsxFqz3dVpAQ=; b=WCZUPCkLj1xBA39oVjLuQu4XYPKBQEjqtrDNBMbivXBCfXGjftu6iaVoVTnceGUGoy mP6s/QecLXnSMjLTXH3lAD95Js7tiptobWLnhaCXY11rSMwrB4BB8V5ElE086BdERHnY pnAYyVBhQKSDapkJ9PlY9LBepnp05tbSOpfZLdYuFTqC4zB5DPZoVGxsYPtQf9kD8yf6 D6uJPwJKtAFnr+2ElHsu8cpaNDA1Zm+P3RwLaTIIzlMgtpz+sM3qkDhJRmZSSe2urbu5 +9waKWrmvhO8uh/d0ZUutyDQGp91pKA1iqE1wCoUR353ZwhXd6w/yhpdfYBPr/mURWFm Es1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:cc; bh=GnR0dKMrZeyAkpIU2Q3Wto3eCDNEauIjsxFqz3dVpAQ=; b=l8fZjHi4AFpxV8SoYqYul2xuRQB+e9ss35nxNafZQnt1RH4scFKau1AZ6SYZrvwcOM mZGRMPWIybMTxbJm+k2Wl45X032yKaagJXjdqjrO/vATbWVACtPQ2kU8ywS9jjIB0Hyy +i5t5hOqQchlWIbjk7d9Ieg2zUWBBrLuajt1RqpESv/a0JNTs/5xysMoxzds47AsAGmq csYkVIwliohd1zEPs388v11Dq6qPMgFE42aQQKfdCtggRZqUJ8NkW0fNuF/k+iqaizR8 9szwpGJ33/Ys7aR1nt3RscG+iCLrpTfu3Uz7+CNi9fzEJBnZMZXgaB2WVzZguCu+dnVW 9iFQ== X-Gm-Message-State: AD7BkJJ5nLqgf6D6He8qWErtYeNQBRz5fR5cEf9Fk3dYBuxOhbuJ9XGPCcWscKTv9p4mpY52QDYyXtktIEUkag== X-Received: by 10.25.156.196 with SMTP id f187mr13282627lfe.150.1458653060960; Tue, 22 Mar 2016 06:24:20 -0700 (PDT) In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:105481 On Wed, Mar 23, 2016 at 12:15 AM, Jussi Piitulainen wrote: > 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)) ... at that point, the genexp is miles ahead in readability :) Although I do sometimes yearn for a "filterout" function that does the same thing as filter() but negates its predicate. Then you could use: next(filterout(str.isspace, stream)) to say "give me the next from the stream, filtering out those which are spaces". It's not hard to write, of course. ChrisA