在另一个列表python中解压缩列表

时间:2015-09-11 20:44:11

标签: python python-2.7

假设你有一个清单:

mylist=[[1,2,3,4],[2,3,4,5],[3,4,5,6]]

任何pythonic(2.x)解压内部列表的方式,以便新列表看起来像?:

mylist_n=[1,2,3,4,2,3,4,5,3,4,5,6]

2 个答案:

答案 0 :(得分:3)

import itertools
mylist=[[1,2,3,4],[2,3,4,5],[3,4,5,6]]
print list(itertools.chain(*mylist))

答案 1 :(得分:2)

mylist_n = [j for i in mylist for j in i]