Python 展平双嵌套列表

Python 展平双嵌套列表,python,list-comprehension,nested-lists,Python,List Comprehension,Nested Lists,如何将其转换为: [[[1,2,3], ['a','b','c']], [[4,5], ['d','e']], [[6,7,8,9], ['f','g','h','i']]] 为此: [[1,2,3,4,5,6,7,8,9], ['a','b','c','d','e','f','g','h','i']] 了解python,一定有办法使用zip和列表理解。看起来像是和的任务 这会给你 [([1, 2, 3], [4, 5], [6, 7, 8, 9]), (['a', 'b', 'c'], [

如何将其转换为:

[[[1,2,3], ['a','b','c']], [[4,5], ['d','e']], [[6,7,8,9], ['f','g','h','i']]]
为此:

[[1,2,3,4,5,6,7,8,9], ['a','b','c','d','e','f','g','h','i']]
了解python,一定有办法使用zip和列表理解。

看起来像是和的任务

这会给你

[([1, 2, 3], [4, 5], [6, 7, 8, 9]), (['a', 'b', 'c'], ['d', 'e'], ['f', 'g', 'h', 'i'])]
现在应用
链。对于内部列表,请从\u iterable

data = [[[1,2,3], ['a','b','c']], [[4,5], ['d','e']], [[6,7,8,9], ['f','g','h','i']]]
print([list(itertools.chain.from_iterable(inner)) for inner in zip(*data)])

zip
与组合,从外观上看。将其作为一个副本关闭,因为除了首先循环
zip(*inputlist)
output,然后将另一个答案应用于其中的每个元素之外,这里没有足够新颖的内容。正如我所说的,只需组合
zip()
我正在写我的答案,而问题被标记为重复,我不想把它扔掉。我现在要检查一下被骗者。
data = [[[1,2,3], ['a','b','c']], [[4,5], ['d','e']], [[6,7,8,9], ['f','g','h','i']]]
print([list(itertools.chain.from_iterable(inner)) for inner in zip(*data)])