Python通过递归遍历出集合中所有元素的方法

yipeiwu_com5年前Python基础

本文实例讲述了Python通过递归遍历出集合中所有元素的方法。分享给大家供大家参考。具体实现方法如下:

复制代码 代码如下:
'''''通过递归遍历出集合中的所有元素
Created on 2013-9-29
@author: L.Eric
''' 
def print_List(list_nums): 
    for each_item in list_nums :  
        if isinstance(each_item,list): 
            print_List(each_item) 
        else: 
            print(each_item) 
movies = ["aaa","bbb","ccc","ddd",["qqq","sss",["mmm","rrr",["tt","ccs"]]]] 
print_List(movies)

希望本文所述对大家的Python程序设计有所帮助。

相关文章

Python实现的微信红包提醒功能示例

本文实例讲述了Python实现的微信红包提醒功能。分享给大家供大家参考,具体如下: #coding=utf-8 import itchat from itchat.content i...

djano一对一、多对多、分页实例代码

昨日内容: ORM高级查询 -filter id=3 id__gt=3 id__lt=3 id__lte=3 id__gte=3 -in /not in .filter(id__i...

python 字典 setdefault()和get()方法比较详解

python 字典 setdefault()和get()方法比较详解

dict.setdefault(key, default=None) --> 有key获取值,否则设置 key:default,并返回default,default默认值为None...

python对常见数据类型的遍历解析

字符串遍历 >>> a_str = "hello itcast" >>> for char in a_str: ... print(char,...

使用python动态生成波形曲线的实现

使用python动态生成波形曲线的实现

效果是这个样子的: 用到的模块: * matplotlib.pyplot * matplotlib.animation.FuncAnimation * numpy 三个圆的半径分...