Tom
Tom

Reputation: 183

How can I do to check if a list of lists is empty?

I have this list :

a = [[], [], []]

and that one :

b = [[], [2], []]

I would like to check if a and b are empty. I mean for me a is empty and b is not. How can I do that ?

Thank you very much !

Upvotes: 0

Views: 68

Answers (2)

Cory Kramer
Cory Kramer

Reputation: 117866

You could check for "empty" using not any

>>> not any(a)
True
>>> not any(b)
False

Upvotes: 1

Jab
Jab

Reputation: 27485

Using any:

>>> any([[], [], []])
False
>>> any([[], [2], []])
True

Upvotes: 1

Related Questions