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()

Leave a Comment