Python: How to check if a nested list is essentially empty?

前端 未结 7 1665
栀梦
栀梦 2020-12-29 05:56

Is there a Pythonic way to check if a list (a nested list with elements & lists) is essentially empty? What I mean by

7条回答
  •  盖世英雄少女心
    2020-12-29 06:09

    Use the any() function. This returns True if any list within the list is not empty.

    alist = [[],[]]
    if not any(alist):
        print("Empty list!")
    
    >> Empty list!
    

    see: https://www.programiz.com/python-programming/methods/built-in/any

提交回复
热议问题