Depth of a list

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.

Problem information

Author: Gabriel Valiente

Generation: 2026-01-25T17:19:59.414Z

© Jutge.org, 2006–2026.
https://jutge.org