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


Groups > comp.lang.python > #91831

Re: for...else

Path csiph.com!usenet.pasdenom.info!bete-des-vosges.org!news.redatomik.org!newsfeed.xs4all.nl!newsfeed1a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <prvs=588e0e812=jeanmichel@sequans.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status UNSURE 0.457
X-Spam-Level ****
X-Spam-Evidence '*H*': 0.19; '*S*': 0.11; 'layout,': 0.16; 'none),': 0.16; 'to:2**1': 0.22; 'code,': 0.23; '2015': 0.23; 'header:In- Reply-To:1': 0.24; 'equivalent': 0.27; 'skip:( 20': 0.28; 'currently,': 0.29; '-----': 0.29; 'sent:': 0.35; 'to:addr:python- list': 0.35; 'subject:': 0.36; 'hi,': 0.37; 'email addr:python.org': 0.37; 'subject:: ': 0.37; 'thank': 0.39; 'to:addr:python.org': 0.39; 'received:194': 0.61; 'information': 0.62; 'matter': 0.63; 'you.': 0.64; 'places': 0.64; 'of:': 0.66; 'person,': 0.66; 'email name:python-list': 0.67; 'privileged.': 0.67; 'notice:': 0.67; 'disclose': 0.71; 'ideas.': 0.84; 'ion': 0.84; 'june,': 0.84; 'medium.': 0.91
X-IronPort-AV E=Sophos;i="5.13,539,1427752800"; d="scan'208";a="4412477"
X-Virus-Scanned amavisd-new at zimbra.sequans.com
Date Tue, 2 Jun 2015 14:01:03 +0200 (CEST)
From Jean-Michel Pichavant <jeanmichel@sequans.com>
To acdr <mail.acdr@gmail.com>, python-list@python.org
In-Reply-To <CANFcO8tOLorV1kuGJo6Vgb-e02EhC3NL2U7oiNRNF+b2s2M2ig@mail.gmail.com>
Subject Re: for...else
MIME-Version 1.0
X-Mailer Zimbra 7.2.7_GA_2942 (ZimbraWebClient - GC37 (Linux)/7.2.7_GA_2942)
Content-Type text/plain; charset="utf-8"
Content-Transfer-Encoding base64
X-Mailman-Approved-At Tue, 02 Jun 2015 14:35:22 +0200
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.20+
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.56.1433248524.13271.python-list@python.org> (permalink)
Lines 21
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1433248524 news.xs4all.nl 2851 [2001:888:2000:d::a6]:59094
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:91831

Show key headers only | View raw


----- Original Message -----
> From: "acdr" <mail.acdr@gmail.com>
> To: python-list@python.org
> Sent: Tuesday, 2 June, 2015 1:26:42 PM
> Subject: for...else
> 
> Hi,
> 
> Currently, in various places in my code, I have the equivalent of:
> 
> for x in it:
>     if complicated_calculation_1():
>         cleanup()
>         break
>     complicated_calculation_2()
>     if complicated_calculation_3():
>         cleanup()
>         break

Hi

With the following layout, adding calculation steps is just a matter of adding a line

for x ion it:
  for calc, cbk in [
    (complicated_calculation_1, cleanup),
    (complicated_calculation_2, None),
    (complicated_calculation_3, cleanup),
  ]:
    if calc() and cbk:
      cbk()
      break
      
It might give you ideas.

JM


-- IMPORTANT NOTICE: 

The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.

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


Thread

Re: for...else Jean-Michel Pichavant <jeanmichel@sequans.com> - 2015-06-02 14:01 +0200

csiph-web