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


Groups > comp.lang.python > #105040

Re: empty clause of for loops

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From "Sven R. Kunze" <srkunze@mail.de>
Newsgroups comp.lang.python
Subject Re: empty clause of for loops
Date Wed, 16 Mar 2016 15:44:27 +0100
Lines 23
Message-ID <mailman.213.1458139469.12893.python-list@python.org> (permalink)
References <mailman.186.1458123807.12893.python-list@python.org> <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 <srkunze@mail.de>
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 <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>
Xref csiph.com comp.lang.python:105040

Show key headers only | View raw


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

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


Thread

empty clause of for loops "Sven R. Kunze" <srkunze@mail.de> - 2016-03-16 11:23 +0100
  Re: empty clause of for loops Steven D'Aprano <steve@pearwood.info> - 2016-03-16 23:08 +1100
    Re: empty clause of for loops "Sven R. Kunze" <srkunze@mail.de> - 2016-03-16 15:44 +0100
  Re: empty clause of for loops André Roberge <andre.roberge@gmail.com> - 2016-03-16 05:41 -0700
    Re: empty clause of for loops Steven D'Aprano <steve@pearwood.info> - 2016-03-16 23:59 +1100
    Re: empty clause of for loops Peter Otten <__peter__@web.de> - 2016-03-16 14:04 +0100
  Re: empty clause of for loops Palpandi <palpandi111@gmail.com> - 2016-03-18 12:10 -0700

csiph-web