码迷,mamicode.com
首页 > 编程语言 > 详细

Python list1

时间:2015-09-15 16:13:53      阅读:166      评论:0      收藏:0      [点我收藏+]

标签:

>>> movies =[
    "the holy grail", 1975,"terry jones",91,
    ["graham chapman",
     ["michel palin","john cheelse","terry gilliam","eric idle","terry jones"]]]
>>> print (movies)
[the holy grail, 1975, terry jones, 91, [graham chapman, [michel palin, john cheelse, terry gilliam, eric idle, terry jones]]]


>>> for each_item in movies:
    if isinstance(each_item,list):
        for nested_item in each_item:
            if isinstance(nested_item,list):    
                for last_item in nested_item:
                    print(last_item)
            else:
                print(nested_item)
    else:
        print(each_item)

        
the holy grail
1975
terry jones
91
graham chapman
michel palin
john cheelse
terry gilliam
eric idle
terry jones

 

Python list1

标签:

原文地址:http://www.cnblogs.com/oskb/p/4810492.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!