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
--
https://mail.python.org/mailman/listinfo/python-list