📜  python flatten list - Python 代码示例

📅  最后修改于: 2022-03-11 14:46:24.507000             🧑  作者: 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]