Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/324.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_Python 3.x - Fatal编程技术网

如何在不使用外部库的情况下在Python中交换多维列表的列和行?

如何在不使用外部库的情况下在Python中交换多维列表的列和行?,python,python-3.x,Python,Python 3.x,比如说: >数据 [[1, 2], [3, 4], [5, 6], [7, 8]] 交换行和列时: >数据 [[1, 3, 5, 7], [2, 4, 6, 8]] 在不使用外部库(如pandas或numpy)的情况下,我如何实现以下目标 data = [[1, 2], [3, 4], [5, 6], [7, 8]] print([*map(list, zip(*data))]) 印刷品: [[1, 3, 5, 7], [2, 4, 6,

比如说:

>数据
[[1, 2],
[3, 4],
[5, 6],
[7, 8]]
交换行和列时:

>数据
[[1, 3, 5, 7],
[2, 4, 6, 8]]
在不使用外部库(如pandas或numpy)的情况下,我如何实现以下目标

data = [[1, 2],
        [3, 4],
        [5, 6],
        [7, 8]]

print([*map(list, zip(*data))])
印刷品:

[[1, 3, 5, 7], [2, 4, 6, 8]]