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
Asked By: kaan46

||

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
Answered By: sj95126

Use any :

print(not any(a))
print(not any(b))

output:

True
False
Answered By: SomeDude

This can work:

for i in a:
    if len(str(i))>0:
        print("With Something")
    else:
        print("empty")
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.