Search code examples
pythonlistif-statementempty-list

How to return True when detecting a nested list of empty lists?


I was trying to return the True value when writing the statement: list = [[],[],[],[]] list == [] Instead it returns False

My nested list consists of a variable number of empty lists. How do I write a single statement that could apply to nested list of [1/2/3...] empty lists?


Solution

  • all(x == [] for x in your_list)
    

    to return True if all empty

    any(x != [] for x in your_list)
    

    to return True if at least on is not empty