写一个段落python代码推理list深浅
2015-10-10 08:24
701 查看
主要是针对嵌套列表问题。 列表套列表,究竟子列表那个更深。。。
这个问题想着就烦。假设嵌套10000万个列表是不是要统计10000个数再排序呢?
最后想了想用 list的extend功能 加上递归函数尝试了一下,代码例如以下:
l1=[1,'a',[1],[2,3,[4,5,[6,7,[7]]]],[2,5,[5,6]],[4],[5],[6]] #l1 = [1, 2, [3, [4, 5], 6, [7, 8,[9, 10], 11], 12], 13] count = 1 def func(l): global count temp_list = [] for l2 in l: if isinstance(l2,list)==True: temp_list.extend(l2) if len(temp_list)>0: count +=1 func(temp_list) func(l1) print count
相关文章推荐
- 安装python解释器
- 关于Python生成器(Generator的yield、next、send)
- leetcode之First Bad Version
- web服务监控邮件告警python程序
- python中else语句的用法
- LintCode -- 不同的二叉查找树(python-O(n)时间复杂度)
- 2015/10/9 Python核编初级部分学习总结
- 下载python的各种扩展库
- Python学习笔记
- [每日一答] [20151009] 一键式安装Python数据分析工具Canopy
- python按日期分类备份文件夹
- 【python问题系列--4】ValueError: operands could not be broadcast together with shapes (100,3) (3,1)
- 2015/10/9 Python基础(21):可调用和可执行对象
- Python抓取糗事百科
- 萤火虫算法-python实现
- 进化策略-python实现
- python2和python3中的编码问题
- python编码问题.
- Python学习笔记<函数式编程>
- python几个内建函数