Python处理多层镶套列表方法

使用”isinstance”区分处理多层列镶套列表.例子:

elvis = ["www","secret","elvis","chan",["Oh",["yes","like"],"love"]]
for list_elvis in elvis:
    if isinstance(list_elvis,list):
        for list2_elvis in list_elvis:
            if isinstance(list2_elvis,list):
                for list3_elvis in list2_elvis:
                    print(list3_elvis)
            else:
                print(list2_elvis)
    else:
        print(list_elvis)

以上记录爱维C文章Python处理多层镶套列表方法的内容…