Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.139 X-Spam-Level: * X-Spam-Evidence: '*H*': 0.78; '*S*': 0.06; 'inspired': 0.05; 'ugly': 0.07; 'operator,': 0.09; 'cc:addr:python-list': 0.11; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'weird': 0.16; 'wrote:': 0.18; 'cc:addr:python.org': 0.22; 'looks': 0.24; 'cc:2**0': 0.24; 'skip:" 20': 0.27; 'header:In- Reply-To:1': 0.27; 'am,': 0.29; 'dec': 0.30; 'message- id:@mail.gmail.com': 0.30; 'comment': 0.34; 'received:google.com': 0.35; 'really': 0.36; 'doing': 0.36; 'filter': 0.38; 'break': 0.61; 'name': 0.63; 'kind': 0.63; 'skip:n 10': 0.64; 'choose': 0.64; 'finally': 0.65; 'customers': 0.66; 'subject:One': 0.74; 'special': 0.74; 'to:none': 0.92; 'insane': 0.93; '2013': 0.98 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 :content-type; bh=+YioPbo5E2xv43KeqXl/sLNu596d7SNdZCZYM+kV9po=; b=LmRB+5uAwWBTf08Ur//nz+qS00XDnnk1DuSTdVi5aM6evJ6nxwuXOQF5RLkDSfibSv kMfyrNUVRSzkwaQ2GwQ521qAF/hc8owHI3tccPnQisCJwq+d9AQy3h294kEGF3QVgSb4 FfDg1G+4iPPVuBUJAmdLYIdzZQwaJZ9TBdQGtEcOqnJt4IbkgWX3qG+CqzA0uzRxlNc/ g0SIlCTmvMZCDMps6bnSshpptJUyByvkBp8hZZ2S7DMs4jME4D1avoGoytj2gOLuWT8q ac7F0zxPGes60SV2SyF1sDvaH21c1Di2uRkRUMZ+dCPSFcdJ0wruhyzaBIq61WLtWUFI fVwQ== MIME-Version: 1.0 X-Received: by 10.66.164.136 with SMTP id yq8mr21316157pab.67.1386597563494; Mon, 09 Dec 2013 05:59:23 -0800 (PST) In-Reply-To: References: <52a282d1$0$30003$c3e8da3$5496439d@news.astraweb.com> Date: Tue, 10 Dec 2013 00:59:23 +1100 Subject: Re: One liners From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 24 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1386597567 news.xs4all.nl 2938 [2001:888:2000:d::a6]:37823 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:61387 On Tue, Dec 10, 2013 at 12:49 AM, Neil Cerutti wrote: > names = (p.name for p in db.query_people() if p.total_purchases > 0) > names = (n.upper() for n in names) > names = (n for n in names if not n.startswith("Q")) > for n in names: > # Finally actually do something. > > Coincidentally it's a nice way to break up an ugly one-liner. I > also really like that if I choose to no longer filter out > customers whose name begins with Q, I can just comment out that > one line. Try doing that with the one-liner version! # With the restriction: for n in (p.name.upper() for n in names if not n.startswith("Q")): # Without the restriction: for n in (p.name.upper() for n in names ):# if not n.startswith("Q")): You just have to use the special "comment-out-partially" operator, which looks like "):#" and is inspired by some kind of insane smiley with weird hair. ChrisA (Anyone got the cheek de-tonguer handy?)