Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!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.015 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'else:': 0.03; 'subject:same': 0.07; 'bug': 0.12; 'arg2,': 0.16; 'elem': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'iterable:': 0.16; 'subject: ?': 0.16; 'wrote:': 0.18; 'mon,': 0.24; 'second': 0.26; 'header:In-Reply-To:1': 0.27; 'start,': 0.30; 'message-id:@mail.gmail.com': 0.30; 'block,': 0.31; "d'aprano": 0.31; 'steven': 0.31; 'this.': 0.32; 'reader': 0.33; 'skip:d 20': 0.34; 'subject:the': 0.34; 'received:google.com': 0.35; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; "you're": 0.61; 'careful': 0.91; '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:to :content-type; bh=B1TfPGkI37/BfRMSoNYDTiG2frEXSthy96LYEQWCMzk=; b=fl17gfM34WMWUlGDzAjm2JHz0IF1ya/s5YBDZbvrR+O1y997Kl/Q35gtuHSZb/rkDi FAa1t/1Ji+8o59rFpm79YYqw4nbAIeF7kiduTK5N0V9eeT/oS8pIQBduAQswE3w+zydt OPKFQ3qZiDA6AAAxqGP1U6h0vIZ1LxRsnuRlkOx+tpGAAnwhHlT+5kTBmKJLbSBPL1F5 +QEMfOXq4Y0Uchit84IwEy+6akcDUymRWvuxDejM9XBqMCuONWreXV+/VS6joydQCC++ 6TcsaSADmOMc+TLeypYPKtymlqrb6+7eySY3QU4lr3oot1iZB3J8W8cMTL/bWYkdQPtV ltNA== MIME-Version: 1.0 X-Received: by 10.66.163.2 with SMTP id ye2mr1341590pab.170.1382959125894; Mon, 28 Oct 2013 04:18:45 -0700 (PDT) In-Reply-To: <526e4700$0$29972$c3e8da3$5496439d@news.astraweb.com> References: <526e4700$0$29972$c3e8da3$5496439d@news.astraweb.com> Date: Mon, 28 Oct 2013 22:18:45 +1100 Subject: Re: how to avoid checking the same condition repeatedly ? From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 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: 30 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1382959135 news.xs4all.nl 15959 [2001:888:2000:d::a6]:35212 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:57811 On Mon, Oct 28, 2013 at 10:14 PM, Steven D'Aprano wrote: > if needs_preprocessing: > for elem in iterable: > # If you change this block, you must remember to change the > # block below too! > preprocess(item) > do_this(item) > do_that(item) > do_something_else(item, arg1, arg2, expression) > do_another_thing(item + arg3, key=whatever) > print(item) > else: > for elem in iterable: > # If you change this block, you must remember to change the > # block above too! > preprocess(item) > do_this(item) > do_that(item) > do_something_else(item, arg1, arg2, expression) > do_another_thing(item, key=whatever) > print(item) > > > The careful reader will notice that there's already a bug in this. For a start, you're preprocessing in the second block... I don't think that was your intentional bug :) ChrisA