empty clause of for loops

Steven D'Aprano steve at pearwood.info
Wed Mar 16 08:08:18 EDT 2016


On Wed, 16 Mar 2016 09:23 pm, 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?


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;

* run the "empty" block if my_iterable becomes empty after the first loop.



-- 
Steven




More information about the Python-list mailing list