来自两个给定列表的2d数组

时间:2017-10-14 06:14:02

标签: python python-2.7 data-structures

我有2个列表

x = [7,6,4,9, ...]
y = [1,2,3,5, ...]

我想在这些列表中创建一个二维数组,其结果是[[x,y],[x,y] ...]

[[7,1],[6,2],[4,3],[9,5], ...]

3 个答案:

答案 0 :(得分:3)

在Python 2.7中

zip(x,y)

Python 3.x

list(zip(x,y))

输出:

[(7, 1), (6, 2), (4, 3), (9, 5),......]

答案 1 :(得分:1)

尝试

[list(z) for z in zip(x, y)]

答案 2 :(得分:0)

这对我有用:

x = [7,6,4,9]
y = [1,2,3,5]
i=0
list = []
for entry in x:
    list.append([x[i],y[i]])
    i = i+1