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

For loop with different variables python

Lets say i have three arrays :

listXYZ = ['X','Y', 'Z']
list123 = ['1','2','3']
listLetter= ['FF','GG','ZZ']

I tried

for list,x,y in listXYZ,list123,listLetter:
print(list,x,y)

and im getting output x,y,z 1,2,3 etc . What i want is for it to print X 1 FF, Y 2 GG etc.
How do i do that ?

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 :

You can use zip() like so:

for x, y, z in zip(listXYZ,list123,listLetter):
    print(x, y, z)

Also please don’t use builtin names as variable names.

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