Home > other >  How to iterate over two array simultaneously in python?
How to iterate over two array simultaneously in python?

Time:09-02

I have two lists of lists and I wanted to iterate simulataneously.The result I am getting now is wrong.

array_1 = [[-3 ,-4],[ 4 ,2],[ 0 ,5]]
array_2 = [[9 ,2], [3 ,9], [0 ,5]]

for coord,expand_coord in zip(array_1,array_2):
    k,m = coord
    i,j = e_coord
    print(k,m,"k,m")
    print(i,j,"i","j")

My result: 
-3 -4 k,m
0 5 i j
4 2 k,m
0 5 i j
0 5 k,m
0 5 i j  

expected result: 
-3 -4 k,m
9 2 i j
4 2 k,m
3 9 i j
0 5 k,m
0 5 i j  

I will be thankful if you could help me for the same,Thank you!

CodePudding user response:

Your code is correct, just make one correction instead of e_coord convert it to expand_cord.

  • Related