For loop with different variables python

Question:

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 I’m 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 ?

Asked By: haduki

||

Answers:

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.

Answered By: keylongx3x0
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.