python 遍历

python遍历嵌套列表

养鱼的猫咪
178
2021-03-08 08:27:36
栏目: 编程语言

python遍历嵌套列表

在python中使用decompose函数对嵌套列表进行遍历,具体方法如下:

def decompose(com):

types = [list, tuple, set]

tmpType = type(com)

if tmpType in types:

for item in com:

decompose(item)

else tmpeType == dict:

for item in com:

decompose(com[item])

else:

print(com)

lis = [["k",["qwe",20,{"k1":["tt",3,"1"]},89],"ab"]]

decompose(lis)

0
看了该问题的人还看了