I need help creating a new list z, where I will have list values as y0, x0, y1, x1, y2, x2, y3 in vertical order as an array.
output: z = [1, 1, 1, 0, 0, 2, 2, 2, 2, 4, 4, 3, 3, 3, 8, 8, 4, 4, 4]
I tried this for loop iteration, but instead of the desired list z, I get only list values as y2, x2.
I really appreciate any help you can provide.
JavaScript
x
6
1
x = [[0, 0], [4, 4], [8, 8]]
2
y = [[1, 1, 1], [2, 2, 2], [3, 3, 3 ], [4, 4, 4]
3
4
for i in range (0, 3):
5
z = [*y[i], *x[i]]
6
Advertisement
Answer
I found the solution as:
JavaScript
1
8
1
from heapq import merge
2
from itertools import count
3
4
x = [[1, 1, 1], [2, 2, 2], [3, 3, 3 ], [4, 4, 4]]
5
y = [[0, 0], [4, 4], [8, 8]]
6
counter = count()
7
z = np.hstack(list(merge(x, y, key=lambda x: next(counter))))
8