I have searched for the answer to my question for hours but still can't find it.
from itertools import cycle
def repeat():
i = [0, 1, 2]
pool = cycle(i)
print(next(pool))
repeat()
Every time I call the function, it gives 0.
I want the function to give 0, 1, 2, 0, 1, 2, 0, 1, 2, repeatedly every time it is called.
I know I can get what I want if I don't use it as a function. But I want to use it as a function.
Any help will be greatly appreciated! Thank you.
I got the idea of using itertools below: Circular list iterator in Python