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程序设计有所帮助。

相关文章

opencv改变imshow窗口大小,窗口位置的方法

如下所示: cv2.HoughLinesP cv2.namedWindow("enhanced",0); cv2.resizeWindow("enhanced", 640, 4...

python datetime中strptime用法详解

python 中datetime中strptime用法,具体代码如下所示: import datetime day20 = datetime.datetime.strptime('2...

在Python中利用Into包整洁地进行数据迁移的教程

在Python中利用Into包整洁地进行数据迁移的教程

动机 我们花费大量的时间将数据从普通的交换格式(比如CSV),迁移到像数组、数据库或者二进制存储等高效的计算格式。更糟糕的是,许多人没有将数据迁移到高效的格式,因为他们不知道怎么(或者不...

使用python-opencv读取视频,计算视频总帧数及FPS的实现

如下所示: 1、计算总帧数 import os import cv2 video_cap = cv2.VideoCapture('ffmpeg_test.avi') fram...

Python实现监控程序执行时间并将其写入日志的方法

本文实例讲述了Python实现监控程序执行时间并将其写入日志的方法。分享给大家供大家参考。具体实现方法如下: # /usr/bin/python # -*- coding:utf-8...