Path: csiph.com!usenet.pasdenom.info!news.redatomik.org!newsfeed.xs4all.nl!newsfeed1a.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: UNSURE 0.229 X-Spam-Level: ** X-Spam-Evidence: '*H*': 0.55; '*S*': 0.01; 'cc:addr:python-list': 0.10; 'function.)': 0.16; 'layout,': 0.16; 'none),': 0.16; 'wrote:': 0.16; 'cc:2**0': 0.21; 'cc:addr:python.org': 0.21; 'cc:no real name:2**0': 0.23; 'code,': 0.23; '2015': 0.23; 'header :In-Reply-To:1': 0.24; 'skip:" 20': 0.26; '(e.g.': 0.27; 'equivalent': 0.27; 'separate': 0.27; 'message- id:@mail.gmail.com': 0.28; 'skip:( 20': 0.28; 'currently,': 0.29; '-----': 0.29; 'lines': 0.30; "can't": 0.32; 'received:google.com': 0.34; 'sent:': 0.35; 'replace': 0.35; 'really': 0.35; 'but': 0.36; 'subject:': 0.36; 'hi,': 0.37; 'email addr:python.org': 0.37; 'subject:: ': 0.37; 'thank': 0.39; '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; 'calculations': 0.84; 'ideas.': 0.84; 'ion': 0.84; 'june,': 0.84; 'medium.': 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:to :cc:content-type; bh=qm4yQF1pG6BviaitCV4WHMdYLNTOMXS7BeDNyouhVXk=; b=CgKn1662wdhLUDY6Hvd8ok+b1nKioMHupiaNM3JUw+4LaW+A5pguX3+Na8ZytMJnRi Hlx6cistqM2UHpIhwikTFz7yEPeWH02B0GHjT7hZqqnvzOnG0Njo8jTDnnBwtVgRDERg 8DVvenvN+ALskXvAyCinx4WA8dLVg8U3l0XDUPad4dDLOcxDwSAy5ubvxe+v1ow4fD6t ME7Y8b/OJf9WssflLF8Rm/ePSWK/eszSY00/hs9ZdSic6Q9pxdu9FZt/Efy/4KBbLnKW vRIgkX0vqyYAfnN0nVn8KvfWmfe4+iRsFWVJUBTX+mM2RDCYQPFBNRSTHkXDdlsU0xDA +p0w== MIME-Version: 1.0 X-Received: by 10.180.106.137 with SMTP id gu9mr31430876wib.54.1433249541874; Tue, 02 Jun 2015 05:52:21 -0700 (PDT) In-Reply-To: <1831776353.1951415.1433246463232.JavaMail.root@sequans.com> References: <1831776353.1951415.1433246463232.JavaMail.root@sequans.com> Date: Tue, 2 Jun 2015 14:52:21 +0200 Subject: Re: for...else From: acdr To: Jean-Michel Pichavant Cc: python-list@python.org Content-Type: text/plain; charset=UTF-8 X-Mailman-Approved-At: Tue, 02 Jun 2015 14:53:58 +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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 54 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1433249640 news.xs4all.nl 2839 [2001:888:2000:d::a6]:48906 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:91834 That would work for my example, but it would only really work if all the calculations are in a nice function. If I just have a block of code, then I can't use it as easily. (E.g. replace "complicated_calculation_2()" by multiple lines of code, which I don't want to shove into a separate function.) On 6/2/15, Jean-Michel Pichavant wrote: > ----- Original Message ----- >> From: "acdr" >> 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. >