Counting depth or the deepest level a nested list goes to
Here is one way to write the function
depth = lambda L: isinstance(L, list) and max(map(depth, L))+1
I think the idea you are missing is to use max()
Let's first rephrase your requirements slightly.
The depth of a list is one more than the maximum depth of its sub-lists.
Now, this can be translated directly to code:
def depth(l):
if isinstance(l, list):
return 1 + max(depth(item) for item in l)
else:
return 0