Count of a list X76287


Statement
 

pdf   zip   main.py

html

The count of a list t is the number of non-list elements that it contains. For example, the count of [′a′, ′b′, ′c′] is 3, the count of [′a′, [′a′, ′a′], ′a′] is 4, the count of [[[′a′]]] is 1, and the count of [] is 0.

Write a program that prints the count of every given list.

Define and use a recursive function

count(t)

that returns the count 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 count of every given list.

Observation You only need to submit the required procedure; your main program will be ignored.

Public test cases
  • Input

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

    Output

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