Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to iterate over two array simultaneously in python?

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!

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading