LearnPy Hub
← Iterators & Generators problems
Hard

Flatten Any Depth

Write a recursive generator flatten(x) that yields every number in a list nested to any depth, using yield from. Read a list literal (use ast.literal_eval) and print the numbers on one line, then how many there are and the deepest nesting level (a plain list is level 1).

Input

One list literal.

Output

Three lines.

Sample 1

Input
[1, [2, [3, [4]]], 5]
Output
1 2 3 4 5
5
4

Sample 2

Input
[]
Output
empty
0
1
solution.py
Output appears here
Flatten Any Depth · Python practice problem · LearnPy Hub