+ 2

using two variables in for loop?

How can we use two variables simultaneously in for loop? for x, y in data1, data2: print(x, y)

13th May 2017, 8:45 AM
buggythegret
buggythegret - avatar
2 Answers
+ 3
You must do nested loop, or eventually if both structures are list with same number of items ( or dict sharing same properties ^^ ), with a loop on the shared indexes ( or keys )... Provide much of your code case context if you want more accurate answer ;)
13th May 2017, 9:48 AM
visph
visph - avatar
0
for x in data1: for y in data2: print(x,y) or if their lengths are same for i in range(0,len(data1)): print(data1[i],data2[i])
13th May 2017, 12:28 PM
SzabĂł GĂĄbor
SzabĂł GĂĄbor - avatar