Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: "Sven R. Kunze" Newsgroups: comp.lang.python Subject: Re: empty clause of for loops Date: Wed, 16 Mar 2016 15:44:27 +0100 Lines: 23 Message-ID: References: <56e94cd9$0$22142$c3e8da3$5496439d@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de z00ySH4oNXPoTCoo3R+QEw9MAS22fAajgpoU62xmT9Bw== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.084 X-Spam-Evidence: '*H*': 0.83; '*S*': 0.00; 'loop.': 0.09; '(at': 0.13; 'suggest': 0.15; 'received:io': 0.16; 'received:psf.io': 0.16; 'something.': 0.16; "tim's": 0.16; 'view)': 0.16; 'wrote:': 0.16; 'header:In-Reply-To:1': 0.24; 'least': 0.27; 'initial': 0.28; "we're": 0.30; 'code': 0.30; 'becomes': 0.30; 'supposed': 0.31; 'run': 0.33; 'point': 0.33; "d'aprano": 0.33; 'steven': 0.33; 'received:10.0': 0.34; 'best,': 0.35; 'but': 0.36; 'to:addr :python-list': 0.36; 'subject:: ': 0.37; 'received:10': 0.37; 'two': 0.37; 'one,': 0.37; 'doing': 0.38; 'mean': 0.38; 'rather': 0.39; 'to:addr:python.org': 0.40; 'where': 0.40; 'received:de': 0.40; 'your': 0.60; 'provide': 0.61; 'charset:windows-1252': 0.62; 'different': 0.63; 'rare': 0.66; 'friends': 0.82; 'imagine': 0.96 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=mail.de; s=mail201212; t=1458139467; bh=+5IC+OKynuaN5xdpUTmI1LAaVxotgH7WUnmBueByF2Y=; h=Subject:To:References:From:Date:In-Reply-To:From; b=Dn5kXm8Ln+hmdZF+xKrkt+9qXwnu8A4RuxDkvJsMgBPX1n+lpyjpuvXePPCpndd18 cXdzOqKqPn0u8N7bEFRvSeACOdo56RqpJtpmLQNFlaj4NRuYG7VBesxD5hAa7i7ny3 F6yEjuX80PP5hGHOlJ+xatZ4Kjz9Ns8nWx9MiXxY= In-Reply-To: <56e94cd9$0$22142$c3e8da3$5496439d@news.astraweb.com> X-purgate: clean X-purgate: This mail is considered clean (visit http://www.eleven.de for further information) X-purgate-type: clean X-purgate-Ad: Categorized by eleven eXpurgate (R) http://www.eleven.de X-purgate: This mail is considered clean (visit http://www.eleven.de for further information) X-purgate: clean X-purgate-size: 825 X-purgate-ID: 154282::1458139467-00003BBD-643208DF/0/0 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:105040 On 16.03.2016 13:08, Steven D'Aprano wrote: > Doing what? What is the code supposed to do? What's "empty" mean as a > keyword? > > If you explain what your friends wants, then perhaps we can suggest > something. Otherwise we're just guessing. I can think of at least two > different meanings: > > * run the "empty" block only if my_iterable is empty at the start of the > first loop; Solutions of most commenters already tackled this one, which is (at least from my point of view) the most intuitive. > * run the "empty" block if my_iterable becomes empty after the first loop. I think I can imagine where this is coming from but this was not the initial use-case. I think Tim's answer (count approach) would provide a solution for this (from my point of view) rather rare use-case. Best, Sven