解决方案:

可以使用包, itertools.chain()

import itertools

list2d = [[1,2,3], [4,5,6], [7], [8,9]]
merged = list(itertools.chain(*list2d))

也可以不使用解包的方法, 使用itertools.chain.from_iterable

merged = list(itertools.chain.from_iterable(list2d))

原文链接: https://stackoverflow.com/questions/952914/how-to-make-a-flat-list-out-of-a-list-of-lists

相关文章:

  • 2022-01-05
  • 2022-01-14
  • 2022-12-23
  • 2022-12-23
  • 2021-12-09
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-06-15
  • 2021-07-14
  • 2022-12-23
  • 2021-07-02
  • 2022-12-23
相关资源
相似解决方案