I have a list that looks like:
a = ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10']
I need to cycle through this list one element at a time but when the end of the list is reached, the cycle needs to be reversed.
For example, using itertools.cycle:
from itertools import cycle
a_cycle = cycle(a)
for _ in range(30):
print a_cycle.next()
I get:
01, 02, 03, 04, 05, 06, 07, 08, 09, 10, 01, 02, 03, 04, 05, 06, 07, 08, 09, 10, 01, 02, 03, 04, 05, 06, 07, 08, 09, 10
but what I need is:
01, 02, 03, 04, 05, 06, 07, 08, 09, 10, 10, 09, 08, 07, 06, 05, 04, 03, 02, 01, 01, 02, 03, 04, 05, 06, 07, 08, 09, 10
I need to cycle through a
for a fixed number of times, say 200.