在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)