Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/jsf/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 按元素联接列表_Python - Fatal编程技术网

Python 按元素联接列表

Python 按元素联接列表,python,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新手)试试(类似问题:): lst列表中的字母是字符还是变量?请使用zipEx:print(zip(*lst))@CarloZanocco我编辑了这个问题,谢谢。这几乎是我想到的解决方

我想通过元素连接列表列表,这样

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新手)

试试(类似问题:):


lst列表中的字母是字符还是变量?请使用
zip
Ex:
print(zip(*lst))
@CarloZanocco我编辑了这个问题,谢谢。这几乎是我想到的解决方案,使用zip函数非常明显。这是你能找到的最好的方法@Andri Már Stefánson这里有解决方案这正是我想要的,谢谢
>>> 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]]