在 python 中将列表加入单个列表(或迭代器)的简短语法是什么?
例如,我有一个如下列表,我想遍历 a、b 和 c。
x = [["a","b"], ["c"]]
我能想到的最好的如下。
result = []
[ result.extend(el) for el in x]
for el in result:
print el
最佳答案
import itertools
a = [['a','b'], ['c']]
print(list(itertools.chain.from_iterable(a)))
关于python - 加入python中的列表列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/716477/