嵌套列表拆分-python

python中嵌套列表的拆分方法

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

例子:

rr = ["1","2d","网址",["see你们","5"]]
for i in flatten(rr):
    print(i)

结果:

1
2d
网址
see你们
5

你可能感兴趣的:(python,python,list)