Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #57811

Re: how to avoid checking the same condition repeatedly ?

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 <rosuav@gmail.com>
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 <mailman.1693.1382953842.18130.python-list@python.org> <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 <rosuav@gmail.com>
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 <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.1695.1382959135.18130.python-list@python.org> (permalink)
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

Show key headers only | View raw


On Mon, Oct 28, 2013 at 10:14 PM, Steven D'Aprano
<steve+comp.lang.python@pearwood.info> 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

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

how to avoid checking the same condition repeatedly ? Wolfgang Maier <wolfgang.maier@biologie.uni-freiburg.de> - 2013-10-28 09:50 +0000
  Re: how to avoid checking the same condition repeatedly ? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-10-28 11:14 +0000
    Re: how to avoid checking the same condition repeatedly ? Chris Angelico <rosuav@gmail.com> - 2013-10-28 22:18 +1100
      Re: how to avoid checking the same condition repeatedly ? Steven D'Aprano <steve@pearwood.info> - 2013-10-29 04:51 +0000
  Re: how to avoid checking the same condition repeatedly ? Piet van Oostrum <piet@vanoostrum.org> - 2013-10-28 14:31 -0400
  Re: how to avoid checking the same condition repeatedly ? Nobody <nobody@nowhere.com> - 2013-10-28 19:37 +0000
    Re: how to avoid checking the same condition repeatedly ? Neil Cerutti <neilc@norwich.edu> - 2013-10-29 13:44 +0000
      Re: how to avoid checking the same condition repeatedly ? rusi <rustompmody@gmail.com> - 2013-10-29 09:13 -0700
  Re: how to avoid checking the same condition repeatedly ? Peter Cacioppi <peter.cacioppi@gmail.com> - 2013-10-28 23:14 -0700
    Re: how to avoid checking the same condition repeatedly ? Chris Angelico <rosuav@gmail.com> - 2013-10-29 17:39 +1100
  Re: how to avoid checking the same condition repeatedly ? Peter Cacioppi <peter.cacioppi@gmail.com> - 2013-10-28 23:53 -0700
    Re: how to avoid checking the same condition repeatedly ? Chris Angelico <rosuav@gmail.com> - 2013-10-29 18:09 +1100
  Re: how to avoid checking the same condition repeatedly ? Peter Cacioppi <peter.cacioppi@gmail.com> - 2013-10-29 16:55 -0700
  Re: how to avoid checking the same condition repeatedly ? alex23 <wuwei23@gmail.com> - 2013-10-30 11:38 +1000
  Re: how to avoid checking the same condition repeatedly ? Mariano Anaya <marianoanaya@gmail.com> - 2013-10-30 06:34 -0700

csiph-web