1. 自带的tkinter模块
from tkinter import _flatten
arr = [[1, 2, 3], [7, 8, 9]]
t = list(_flatten(arr))
print(t)
>>> [1, 2, 3, 7, 8, 9]
  1. 自带的itertools模块
arr = [[1, 2, 3], [7, 8, 9]]
t = list(chain.from_iterable(arr))
print(t)
>>> [1, 2, 3, 7, 8, 9]
  1. 用sum对列表的求和
arr = [[1, 2, 3], [7, 8, 9]]
t = sum(arr, [])
print(t)
>>> [1, 2, 3, 7, 8, 9]
Logo

讨论HarmonyOS开发技术,专注于API与组件、DevEco Studio、测试、元服务和应用上架分发等。

更多推荐