0

I have below lists

list1 = ['a1', 'a2', 'a3', 'a4', 'a5', 'a6']
list2 = [1, 2, 3]

Code:

>>> for i, x in enumerate(zip(list1, list2)):
...     a = list1[i]
...     b = list1[i + 1]
...     print a, b
...

output:

a1 a2
a2 a3
a3 a4

Expected output:

a1 a2
a3 a4
a5 a6

Please help

meteor23
  • 267
  • 3
  • 6
  • 11

1 Answers1

1

Easiest fix:

for i, x in enumerate(zip(list1, list2)):
    a = list1[i*2]
    b = list1[i*2 + 1]
    print a, b

Output:

a1 a2
a3 a4
a5 a6
jerrycheng
  • 167
  • 8
  • I don't know the use of _list2_ here, if you just want to select elements in list with a range, `for slice in map(lambda i:l[2*i:2*(i+1)], range(3)): print(slice)` – letmecheck Jun 01 '18 at 05:48