https://docs.python.org/3/library/itertools.html#itertools.cycle
For example:
>>> import itertools
>>> number_of_flashes = 4
>>> flash_cycle = itertools.cycle(range(number_of_flashes))
>>> flash_cycle
<itertools.cycle object at 0x00000163FEBF2F80>
>>> next(flash_cycle)
0
>>> next(flash_cycle)
1
>>> next(flash_cycle)
2
>>> next(flash_cycle)
3
>>> next(flash_cycle)
0
>>> next(flash_cycle)
1
>>> next(flash_cycle)
2
>>> next(flash_cycle)
3
>>> next(flash_cycle)
0
https://docs.python.org/3/library/itertools.html#itertools.cycle
For example: