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


Groups > comp.lang.python > #105235

Re: empty clause of for loops

Newsgroups comp.lang.python
Date 2016-03-18 12:10 -0700
References <mailman.186.1458123807.12893.python-list@python.org>
Message-ID <e68d7749-da7d-45a6-b7fd-153540631945@googlegroups.com> (permalink)
Subject Re: empty clause of for loops
From Palpandi <palpandi111@gmail.com>

Show all headers | View raw


On Wednesday, March 16, 2016 at 3:53:48 PM UTC+5:30, Sven R. Kunze wrote:
> Hi,
> 
> a colleague of mine (I write this mail because I am on the list) has the 
> following issue:
> 
> 
> for x in my_iterable:
>      # do
> empty:
>      # do something else
> 
> 
> What's the most Pythonic way of doing this?
> 
> Best,
> Sven

You can do like this.

if not my_iterable:
    <do something>
for x in my_iterable:
    <do something>

Back to comp.lang.python | Previous | NextPrevious 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