【python】多个list合并

来源:互联网 发布:流光屏是什么软件 编辑:程序博客网 时间:2024/06/03 19:28

环境:win7 + python3.5.2

方法一:标准库

from itertools import chaina = [[1,2],[3,4]]a_ = list(chain(*a))print(a_)

运行结果:

[1,2,3,4]

方法二:python风格的写法

a = [[1,2],[3,4]]a_ = [x for j in a for x in j]print(a_)

运行结果:

[1,2,3,4]
0 0
原创粉丝点击