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

yipeiwu_com6年前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 深入理解yield

只是粗略的知道yield可以用来为一个函数返回值塞数据,比如下面的例子: ˂!-- Code highlighting produced by Actipro CodeHighligh...

Python 闭包,函数分隔作用域,nonlocal声明非局部变量操作示例

本文实例讲述了Python 闭包,函数分隔作用域,nonlocal声明非局部变量操作。分享给大家供大家参考,具体如下: 实例对象也可以实现闭包的功能,不过实例对象消耗的资源(内存)比闭包...

python和shell变量互相传递的几种方法

python -> shell: 1.环境变量 复制代码 代码如下:import os  var=123或var='123'os.environ['var']=str(v...

将string类型的数据类型转换为spark rdd时报错的解决方法

在将string类型的数据类型转换为spark rdd时,一直报这个错,StructType can not accept object %r in type %s” % (obj, t...

python实现数通设备tftp备份配置文件示例

  环境:【wind2003[open Tftp server] + virtualbox:ubuntn10 server】tftp : Open TFTP Server&nb...