1

I have 2 lists

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

I would like to create a 2d array out of those lists where the result would like [[x,y],[x,y] ...]

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

3 Answers3

3

In Python 2.7

zip(x,y)

Python 3.x

list(zip(x,y))

Output:

[(7, 1), (6, 2), (4, 3), (9, 5),......]
Transhuman
  • 3,527
  • 1
  • 9
  • 15
1

Try

[list(z) for z in zip(x, y)]
dslack
  • 835
  • 6
  • 17
0

This worked for me:

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
Schwarzy1
  • 31
  • 4