Count the nested depths of the list. That's because it was fallen.
I just added a line to the one that was dropped to count the empty list.
def depth(l):
if isinstance(l, list):
if l == [] : return 1 # count a empty list
return 1 + max(depth(item) for item in l)
else:
return 0
if __name__ == "__main__":
l = ["1",[],"42",["2","13",["2","3",[]],["4"]],["2",[" "],"3"],"3"]
print depth(l)
Recommended Posts