What is the easiest way to detect if a list contains only empty arrays?
Question:
What is the easiest way to check a list of arrays to see if the arrays they contain are all empty?
For example, this is what the arrays look like and the following output is what I would expect:
a = [[],[]] ==> True
b = [["x"], ["y"], []] ==> False
Answers:
Presuming that you know that the list only contains other lists (which do not themselves contain lists), this is one way:
>>> not any(a)
True
>>> not any(b)
False
This can work:
for i in a:
if len(str(i))>0:
print("With Something")
else:
print("empty")
What is the easiest way to check a list of arrays to see if the arrays they contain are all empty?
For example, this is what the arrays look like and the following output is what I would expect:
a = [[],[]] ==> True
b = [["x"], ["y"], []] ==> False
Presuming that you know that the list only contains other lists (which do not themselves contain lists), this is one way:
>>> not any(a)
True
>>> not any(b)
False
This can work:
for i in a:
if len(str(i))>0:
print("With Something")
else:
print("empty")