[Solved] return list 10 times with for. I want 2 numbers to be printed on the screen in each cycle in order [closed]


If you want to cycle the list elements, you can use itertools.cycle. We can call next twice on each iteration to get two numbers at a time from the iterator.

from itertools import cycle

a = cycle([0,1,2,3,4,5,6])

for _ in range(10):
    print(f"{next(a)} - {next(a)}")

Output:

0 - 1
2 - 3
4 - 5
6 - 0
1 - 2
3 - 4
5 - 6
0 - 1
2 - 3
4 - 5

solved return list 10 times with for. I want 2 numbers to be printed on the screen in each cycle in order [closed]