可能重复:
Making a flat list out of list of lists in Python
Join a list of lists together into one list in Python
我有很多列表,看起来像这样
['it']
['was']
['annoying']
我希望上面的代码看起来像这样
['it', 'was', 'annoying']
我该如何做到这一点?
发布于 2012-07-20 14:58:52
import itertools
ab = itertools.chain(['it'], ['was'], ['annoying'])
list(ab)
只是另一种方法...
发布于 2012-07-20 14:49:38
发布于 2012-07-20 14:50:23
a = ['it']
b = ['was']
c = ['annoying']
a.extend(b)
a.extend(c)
# a now equals ['it', 'was', 'annoying']
https://stackoverflow.com/questions/11574195
复制相似问题