python 如何用循环遍历多重列表
a=["li",["mark","jim","lily",["lucy","gao"]],"master"]如何用循环语句遍历打印出limarkjimlilylucyga...
a = ["li",["mark","jim","lily",["lucy","gao"]],"master"]
如何用循环语句遍历
打印出
li
mark
jim
lily
lucy
gao
master
我用三重循之后打印成单个字符了 展开
如何用循环语句遍历
打印出
li
mark
jim
lily
lucy
gao
master
我用三重循之后打印成单个字符了 展开
2个回答
展开全部
>>> def my_print(s):
....... if type(s) == str:
... ..........print s
... .....else:
... ..........for i in s:
... ..........。。。my_print(i)
...
>>> d = ['li', ['mark', 'jim', 'lily', ['lucy', 'gao']]]
>>> my_print(d)
li
mark
jim
lily
lucy
gao
>>>
....... if type(s) == str:
... ..........print s
... .....else:
... ..........for i in s:
... ..........。。。my_print(i)
...
>>> d = ['li', ['mark', 'jim', 'lily', ['lucy', 'gao']]]
>>> my_print(d)
li
mark
jim
lily
lucy
gao
>>>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
自定义函数递归吧:
def myprint(a):
____for i in a:
________if isinstance(i,list):
____________myprint(i)
________else:
____________print i
a = ["li",["mark","jim","lily",["lucy","gao"]],"master"]
myprint(a)
>>>
li
mark
jim
lily
lucy
gao
master
def myprint(a):
____for i in a:
________if isinstance(i,list):
____________myprint(i)
________else:
____________print i
a = ["li",["mark","jim","lily",["lucy","gao"]],"master"]
myprint(a)
>>>
li
mark
jim
lily
lucy
gao
master
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询