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


Groups > comp.lang.python > #104999

RE: empty clause of for loops

From Joaquin Alzola <Joaquin.Alzola@lebara.com>
Newsgroups comp.lang.python
Subject RE: empty clause of for loops
Date 2016-03-16 10:28 +0000
Message-ID <mailman.187.1458124117.12893.python-list@python.org> (permalink)
References <56E93413.6090108@mail.de>

Show all headers | View raw


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@python.org] On Behalf Of Sven R. Kunze
Sent: 16 March 2016 10:23
To: Python List <python-list@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.

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


Thread

RE: empty clause of for loops Joaquin Alzola <Joaquin.Alzola@lebara.com> - 2016-03-16 10:28 +0000

csiph-web