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

Discussão em 'Python' iniciado por Stack, Setembro 29, 2024.

  1. Stack

    Stack Membro Participativo

    Is there a Pythonic way to check if a list (a nested list with elements & lists) is essentially empty? What I mean by empty here is that the list might have elements, but those are also empty lists.

    The Pythonic way to check an empty list works only on a flat list:

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


    For example, all the following lists should be positive for emptiness:

    alist = []
    blist = [alist] # [[]]
    clist = [alist, alist, alist] # [[], [], []]
    dlist = [blist] # [[[]]]

    Continue reading...

Compartilhe esta Página