Problem1088--列表递归降维

1088: 列表递归降维

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 675  Solved: 470
[Submit] [Status] [Web Board] [Creator:]

Description

编写一个返回生成器的方法,将多维列表降到一维。


Input

输入多行,表示多个需要降维的列表。

Output

输出多行,对应输入的行数,输出降维后的列表。

Sample Input

[1, [2, [3, [4]], 5]]
[[1, 2, 3], [4, 5, 6], [7], (8, 9)]

Sample Output

[1, 2, 3, 4, 5]
[1, 2, 3, 4, 5, 6, 7, 8, 9]

HINT

如果不知道从何入手的话,请适当修改如下代码:  
from collections import Iterable
def flatten_deep(lst):
    for i in lst:
        if isinstance(i, Iterable):
            yield from flatten_deep(i)
        else:
            yield i


Source/Category


[Submit] [Status]