I have a nested list and I want to return the number of nested list (or the depth) and the element value if the depth reaches 0. For example, with below nested list, the value I want to return is (13, 37). But my code returns 36 only.
nested = [[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[13]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]
def search(a, depth=0):
count = 0
for e in a:
if isinstance(e, list):
count = count + 1 + search(e)
return count
search(nested)
How should correct my code to make it return (13, 37) as expected?