Experts want your help to Optimize code:
def foo(start, end): index = 0 is_lower = False while index < (len(start)): if is_lower and start[index] == '0': break if not is_lower and start[index] < end[index]: first_lower = index is_lower = True index += 1 return index-1, first_lower start = '37282842000' end = '37282871999' result = [] while int(start) < int(end): index, first_lower = foo(start, end) range_end = index > first_lower and 10 or int(end[first_lower]) for x in range(int(start[index]), range_end): result.append(start[:index] + str(x) ) if range_end == 10: start = str(int(start[:index])+1)+'0'+start[index+1:] else: start = start[:index] + str(range_end) + start[index+1:] print (result) ~~~~ How to modify above code to give below output: 37282842 37282843 37282844 37282845 37282846 37282847 37282848 37282849 3728285 3728286 37282870 37282871