Depth of a list X62244


Statement
 

pdf   zip

The depth of a list tt is the maximum number of nestings of lists that it contains. For example, the depth of [a,b,c][a, b, c] is 1, the depth of [a,[b,c],d][a, [b, c], d] is 2, and the depth of [[[a]]][[[a]]] 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 tt.

Hint

Using the @ast@ package, you can extract the list tt encoded in a string ss with @t = ast.literal_eval(s)@.

Input

The input consists of several lists.

Output

Print the depth of every given list.

Public test cases
  • Input

    []
    ['a', 'b', 'c']
    ['a', ['b', 'c'], 'd']
    [[['a']]]
    

    Output

    0
    1
    2
    3
    
  • Information
    Author
    Gabriel Valiente
    Language
    English
    Official solutions
    Python
    User solutions
    Python