python3 将二维列表转换为一维列表
自带的tkinter模块from tkinter import _flattenarr = [[1, 2, 3], [7, 8, 9]]t = list(_flatten(arr))print(t)>>> [1, 2, 3, 7, 8, 9]自带的itertools模块arr = [[1, 2, 3], [7, 8, 9]]t = list(chain..
·
- 自带的tkinter模块
from tkinter import _flatten
arr = [[1, 2, 3], [7, 8, 9]]
t = list(_flatten(arr))
print(t)
>>> [1, 2, 3, 7, 8, 9]
- 自带的itertools模块
arr = [[1, 2, 3], [7, 8, 9]]
t = list(chain.from_iterable(arr))
print(t)
>>> [1, 2, 3, 7, 8, 9]
- 用sum对列表的求和
arr = [[1, 2, 3], [7, 8, 9]]
t = sum(arr, [])
print(t)
>>> [1, 2, 3, 7, 8, 9]
更多推荐
已为社区贡献1条内容
所有评论(0)