14767 - Doctor's files   

Description

Doctor is currently cleaning the computer that contain's all of Rhode Island patient's data, but the files are hidden so deep no one but you can retrieve it and help Doctor organize them again.

Your task now is to traverse the file tree and retrieve them in a special order called "PreOrder". By that order means that you have to print out the name of the folder first before going in to its content.

For example:

 

Doctor need to give this list to Kal'tsit - Doctor's boss, so your code MUST abide by this code template, and the function gen MUST also be a generator function, meaning that it can only use yield statement to return value.

 

from ast import literal_eval

def gen(tree: tuple):
    """
    The tree is a tuple (data, [child1, child2, ...])
    Each child is its own tree
    The list of childs can be empty.
    """

genVar = gen(literal_eval(input()))
while True:
    try:
        print(next(genVar))
    except StopIteration:
        break

Hint: Use yield from to yield recursively.

Input

Complete the function gen with the template code.

Output

Generate the list in "Preoder" order.

Sample Input  Download

Sample Output  Download




Discuss