The depth of a list is the maximum number of nestings of lists that it contains. For example, the depth of is 1, the depth of is 2, and the depth of is 3. The depth of is defined to be 0.
Write a program that prints the depth of every given list.
Define and use a recursive function
depth(t)
that returns the depth of a list .
Using the @ast@ package, you can extract the list encoded in a string with @t = ast.literal_eval(s)@.
The input consists of several lists.
Print the depth of every given list.
Input
[] ['a', 'b', 'c'] ['a', ['b', 'c'], 'd'] [[['a']]]
Output
0 1 2 3