按元素加入列表列表

时间:2019-02-27 09:39:32

标签: python

我想按这样的元素加入列表列表

lst = [['a','b','c'], [1,2,3], ['x','y','z'], [4,5,6]]

成为

res = [['a',1,'x',4], ['b',2,'y',5], ['c',3,'z',6]]

我尝试使用列表理解,连接和映射,但是还没有运气。 (是python的新手)

1 个答案:

答案 0 :(得分:3)

尝试zip(类似的问题:Transpose list of lists):

>>> lst = [["a","b","c"], [1,2,3], ["x","y","z"], [4,5,6]]
>>> res = [list(zipped) for zipped in zip(*lst)]
>>> res
[['a', 1, 'x', 4], ['b', 2, 'y', 5], ['c', 3, 'z', 6]]