In Django templates, For loop
has a empty
conditions which gets set only when the object you are looping over is empty.
e.g:
{% for x in my_list %}
#do something
{% empty %}
<p> my_list is empty </p>
{% endfor %}
here if my_list is empty then it will just print my_list is empty
Is there something equivalent in python?
I am using if-else conditions but that's ugly looking. I am trying to find a solution that does not involve using a if-else condition
my current code:
if len(my_list):
for x in my_list:
doSomething()
else:
print "my_list is empty"