Skip to content

Latest commit

 

History

History
23 lines (20 loc) · 475 Bytes

135.md

File metadata and controls

23 lines (20 loc) · 475 Bytes
@author jackzhenguo
@desc
@tag
@version 
@date 2020/02/02

135 列表全展开(生成器版)

#多层列表展开成单层列表
a=[1,2,[3,4,[5,6],7],8,["python",6],9]
def function(lst):
    for i in lst:
        if type(i)==list:
            yield from function(i)
        else:
            yield i
print(list(function(a))) # [1, 2, 3, 4, 5, 6, 7, 8, 'python', 6, 9]
[上一个例子](134.md) [下一个例子](136.md)