lundi 26 septembre 2016

How do I check for an empty nested list in Python?

Say I have a list like

   cata = [["Shelf", 12, "furniture", [1,1]],
          ["Carpet", 50, "furnishing", []]]

and I want to find out in each nested list if it's empty or not.

I am aware of using for loops to iterate through the lists, and if statements to verify as I have in a function

    def myfunc(cata):
       for inner in cata:
           for inner_2 in inner[3]:
               if inner_2:
                    return "True"
               else:
                    return "False"

However instead of returning

    'True'
    'False'

All I get is

   'False'

Is there some method of searching nested loops that I'm missing?

Aucun commentaire:

Enregistrer un commentaire