You can utilize a generator to build a list of times at 30 minute intervals.
def yield_times():
start = datetime.combine(date.today(), time(0, 0))
yield start.strftime("%H:%M:%S")
while True:
start += timedelta(minutes=30)
yield start.strftime("%H:%M:%S")
Using this generator, we can create a list of tuples. 48 in this case, is the number of iterations through the generator. This range statement will start at 0, giving us values 0 - 47.
gen = yield_times()
tuple_list = []
for ii in range(48):
tuple_list.append((ii, gen.next()))
Finally, we need to convert the list of tuples to a tuple of tuples:
tuple_times = tuple(tuple_list)
Full script:
from datetime import date, time, datetime, timedelta
def yield_times():
start = datetime.combine(date.today(), time(0, 0))
yield start.strftime("%H:%M:%S")
while True:
start += timedelta(minutes=30)
yield start.strftime("%H:%M:%S")
gen = yield_times()
tuple_list = []
for ii in range(48):
tuple_list.append((ii, gen.next()))
tuple_times = tuple(tuple_list)