yield from

Lab Python Advanced 30 points

Write a generator walk(tree) that yields every value in a nested list, using yield from for sub-lists. Read a nested list literal and print the values.

Input

One nested list.

Output

One line.

Example

Input

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

Output

1 2 3 4 5
Sample input available Sample output available
Editor
Python

Hints

yield from other_generator() yields everything the other generator produces.

Solution explanation

yield from delegates to a sub-generator, which makes recursive generators simple.

Show solution
import ast


def walk(tree):
    for item in tree:
        if isinstance(item, list):
            yield from walk(item)
        else:
            yield item


print(*walk(ast.literal_eval(input())))
Output
Answer
HOME LEARN COMMUNITY DASHBOARD