Depth of a list X62244


Statement
 

pdf   zip

html

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

Hint

Using the ast package, you can extract the list t encoded in a string s 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