6-01 3,344 views
递归打印多维列表
__author__ = 'Administrator'
cast = ['a','b','c','d',['aa','bb','cc',['aaa','bbb','ccc']]]
print(cast)
def print_lol(the_list):
for each_item in the_list:
if isinstance(each_item,list):
print_lol(each_item)
else:
print(each_item)
print_lol(cast)
"打印结果"
[‘a’, ‘b’, ‘c’, ‘d’, [‘aa’, ‘bb’, ‘cc’, [‘aaa’, ‘bbb’, ‘ccc’]]]
a
b
c
d
aa
bb
cc
aaa
bbb
ccc
a
b
c
d
aa
bb
cc
aaa
bbb
ccc