Python3中多维list压缩为一维,相当于Python2 中的flatten()

版权声明: https://blog.csdn.net/qq_21578125/article/details/81116631
import collections
def flatten(lst):
    for item in lst:
        if isinstance(item,collections.Iterable)and not isinstance(item,(str,bytes)):
            yield from flatten(item)
        else:
            yield item

没有更多推荐了,返回首页