empty clause of for loops

Joaquin Alzola Joaquin.Alzola at lebara.com
Wed Mar 16 06:28:28 EDT 2016


You could do something like ...

If len(my_iterable) is not 0:
for x in my_iterable:
     # do
else:
     # do something else

There should be a more code efficient way to do this.

-----Original Message-----
From: Python-list [mailto:python-list-bounces+joaquin.alzola=lebara.com at python.org] On Behalf Of Sven R. Kunze
Sent: 16 March 2016 10:23
To: Python List <python-list at python.org>
Subject: empty clause of for loops

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
--
https://mail.python.org/mailman/listinfo/python-list
This email is confidential and may be subject to privilege. If you are not the intended recipient, please do not copy or disclose its content but contact the sender immediately upon receipt.



More information about the Python-list mailing list