Reputation: 83
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
Upvotes: 2
Views: 50
Reputation: 998
This can work:
for i in a:
if len(str(i))>0:
print("With Something")
else:
print("empty")
Upvotes: 0
Reputation: 14228
Use any
:
print(not any(a))
print(not any(b))
output:
True
False
Upvotes: 3
Reputation: 6908
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
Upvotes: 2