Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
可能重复: 从 Python 中的列表列表中制作一个平面列表 将列表 列表一起加入 Python 中的一个列表
我有很多看起来像的列表
['it'] ['was'] ['annoying']
我希望上面看起来像
['it', 'was', 'annoying']
我该如何做到这一点?
import itertools ab = itertools.chain(['it'], ['was'], ['annoying']) list(ab)
只是另一种方法......
只需添加它们:
['it'] + ['was'] + ['annoying']
你应该阅读Python 教程来学习这样的基本信息。
a = ['it'] b = ['was'] c = ['annoying'] a.extend(b) a.extend(c) # a now equals ['it', 'was', 'annoying']