📜  展平列表 python 代码示例

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

代码示例6
def flatten(L):
    for item in L:
        try:
            yield from flatten(item)
        except TypeError:
            yield item

list(flatten([[[1, 2, 3], [4, 5]], 6]))
>>>[1, 2, 3, 4, 5, 6]