其他分享
首页 > 其他分享> > 递归处理['a-',['b-',['c','d'],'e-f','d']]

递归处理['a-',['b-',['c','d'],'e-f','d']]

作者:互联网

dd = ['a-',['b-',['c','d'],'e-f','d']]
def sss(dd):
    dl=[]
    print('fff',dd)
    for index,var in enumerate(dd):

        if  isinstance(var,str):
            if var.endswith('-'):
                print(var)
                dl.extend([f'{var}{li}' for li in sss(dd[index+1])])
                print(dl)
            else:
                print('xxx',var)
                dl.append(var)
    return dl
d1 = sss(dd)
print(d1)

标签:index,dl,递归,处理,dd,sss,print,var
来源: https://www.cnblogs.com/mqhpy/p/14523923.html