📌  相关文章
📜  在python代码示例中将2级嵌套列表转换为一级列表

📅  最后修改于: 2022-03-11 14:45:28.910000             🧑  作者: Mango

代码示例1
>>> from collections import Iterable
>>> def flat(lst):
...     for parent in lst:
...         if not isinstance(i, Iterable):
...             yield parent
...         else:
...             for child in flat(parent):
...                 yield child
...
>>> list(flat(([1,[2,2,2],4]))
[1, 2, 2, 2, 4]