Possible Duplicate:
Flattening a shallow list in Python
假设我有一个列表列表。
mylistOfLists = [[1, 2], [3, 4], [5, 6], [7, 8]]
python中获得此结果的最优雅方法是什么?
myCombinedList = [1, 2, 3, 4, 5, 6]
感谢您的任何建议!
最佳答案
myCombinedList = []
[myCombinedList.extend(inner) for inner in mylistOfLists]
要么:
import itertools
myCombinedIterable = itertools.chain.from_iterable(mylistOfLists)
myCombinedList = list(myCombinedIterable)