溫馨提示×

python遍歷嵌套列表

養(yǎng)魚的貓咪
178
2021-03-08 08:27:36
欄目: 編程語言

python遍歷嵌套列表

在python中使用decompose函數(shù)對嵌套列表進(jìn)行遍歷,具體方法如下:

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