import sys sys.setrecursionlimit(2000) #Non Recursive def bubble_sort(array): swap = True end = len(array) - 1 while swap == True: swap = False for i in range(end): if array[i] > array[i+1]: temp = array[i] array[i] = array [i+1] array[i+1] = temp swap = True return array #Recursive: ##def bubble_sort(array,swap): ## if swap == False: ## return array ## swap = False ## end = len(array) - 1 ## for i in range(end): ## if array[i] > array[i+1]: ## temp = array[i] ## array[i] = array[i+1] ## array[i+1] = temp ## swap = True ## ## return bubble_sort(array,swap) file = open("townlist.txt","r") townlist = [] for line in file: town = line.strip() town = town.lower() townlist.append(town) #Non Recursive print(bubble_sort(townlist)) #Recursive ##swap = True ##print(bubble_sort(townlist, swap))