If a listener is empty, and the function is to use list elements, you do not need to do and - the body of for
that will use the list will simply not run.
def funcao(x):
for lista in x:
for elemento in lista:
# fazer coisas
funcao((a, b))
Ready, in the event that "a" is an empty list the internal% wc will simply not be executed.
In other situations you may want to go through some other value in case your variable is an empty list, or None, or another false value. In this case, you can use the short circuit of the for
operator - in the same way that it is used in lignations with the syntax derived from C (which use or
as the "or" operator).
In this case, they could not be used directly in
||
: it would give an error saying that
None
is not interoperable:
/ p>
funcao((a or [], b or []))
(to call the same function as above, ensuring that each element is iterable).