标签:pre put python too ble 一个 iterable int bsp
您可以通过使用itertools
包中的itertools.chain.from_iterable
轻松快速的辗平一个列表。下面是一个简单的例子:
a_list = [[1, 2], [3, 4], [5, 6]]
print(list(itertools.chain.from_iterable(a_list)))
# Output: [1, 2, 3, 4, 5, 6]
# or
print(list(itertools.chain(*a_list)))
# Output: [1, 2, 3, 4, 5, 6]
标签:pre put python too ble 一个 iterable int bsp
原文地址:http://www.cnblogs.com/hyu9999/p/7515665.html