python3删除了flatten包
但可用一下代码段代替
import collections
def flatten(x):
result = []
for elin x:
if isinstance(x, collections.Iterable)and not isinstance(el,str):
result.extend(flatten(el))
else:
result.append(el)
return result
print(flatten(["junk", ["nested stuff"], [], [[]]]))
网友评论