import time j = 1 for classperiod in periods: try: startTime = time.strptime(classperiod[0], "%I:%M %p") except ValueError: try: startTime = time.strptime(classperiod[0], "%I:%M%p") except ValueError: startTime = time.strptime(classperiod[0],"%H:%M") try: endTime = time.strptime(classperiod[1], "%I:%M %p") except ValueError: try: endTime = time.strptime(classperiod[1], "%I:%M%p") except ValueError: endTime = time.strptime(classperiod[1], "%H:%M")