Python 代码阅读合集介绍:为什么不推荐Python初学者直接看项目源码
本篇阅读的代码实现了将一个嵌套列表的所有嵌套层次完全展开,形成一个简单的列表的功能。
本篇阅读的代码片段来自于30-seconds-of-python。
deep_flatten
from collections.abc import Iterable
def deep_flatten(lst):
return [a for i in lst for a in deep_flatten(i)] if isinstance(lst, Iterable) else [lst]
# EXAMPLES
deep_flatten(