如何在python中将多个列表合并为一个列表?

How to merge multiple lists into one list in python?

本问题已经有最佳答案,请猛点这里访问。

Possible Duplicate:
Making a flat list out of list of lists in Python
Join a list of lists together into one list in Python

我有很多清单

1
2
3
['it']
['was']
['annoying']

我想让上面看起来像

1
['it', 'was', 'annoying']

我怎样才能做到?


只需添加它们:

1
['it'] + ['was'] + ['annoying']

您应该阅读python教程来学习这样的基本信息。


1
2
3
import itertools
ab = itertools.chain(['it'], ['was'], ['annoying'])
list(ab)

只是另一种方法……


1
2
3
4
5
6
7
8
a = ['it']
b = ['was']
c = ['annoying']

a.extend(b)
a.extend(c)

# a now equals ['it', 'was', 'annoying']