-2

My goal is to combine some for loops.

for example,

v1=[1,2]
v2=[6,7]

for i,j in v1,v2:
    print(i)
    print(j)

It should be printed:

1
6
2
7
iacob
  • 20,084
  • 6
  • 92
  • 119
Alex
  • 41
  • 5

2 Answers2

2

You want to use zip here:

v1=[1,2]
v2=[6,7]

for i,j in zip(v1,v2):
    print(i)
    print(j)
iacob
  • 20,084
  • 6
  • 92
  • 119
-1

You can go:

for i in range(len(v1)): # Assuming both v1 and v2 are the same length.
    print(v1[i])
    print(v2[i])

Hope it helps.

Elodin
  • 650
  • 5
  • 23