names = ['A','B','C',['D','E'],['F']] def print_lol(the_list,indent=False,level=0): # for each_item in the_list: if isinstance(each_item,list): print_lol(each_item,indent,level+1) else: if indent: for tab_top in range(level): print(" ",end='') print(each_item)
print_lol(names,True,4) #首行缩进4格输出
A B C D E F
print_lol(names,True)
A
B
C
D
E
F
print_lol(names)
A B C D E F