给定一个嵌套列表/元组列表,返回单个列表中的所有元素
FlattenList的Python项目详细描述
给定一个嵌套列表/元组列表,返回单个列表中的所有元素。 典型用法:
#!/usr/bin/env python from flatten.flatten import flattenlist the_list = [[1,2,3],[4,5,6], [7], [8,9]] flattenlist(the_list) [1, 2, 3, 4, 5, 6, 7, 8, 9]
简介
这个问题已经有很多实现,如下所示。
热情的matplotlib。如果您安装了MatplotLib或Enthough Canopy,扁平化模块使用:
from matplotlib.cbook import flatten
以上代码的主要接收者如下:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/121294
- 在此堆栈溢出问题中尝试使用此模块:
http://stackoverflow.com/questions/406121/flattening-a-shallow-list-in-python/20400584#20400584
flattenlist是一个普通的python尝试,在没有任何外部模块开销的情况下获得相同的结果。