def insertion_sort(array): for marker in range(len(array)-1): for i in range(marker + 1, 0, -1): if array[i] < array[i-1]: temp = array[i] array[i] = array[i-1] array[i-1] = temp return array file = open("townlist.txt","r") townlist = [] for line in file: town = line.strip() town = town.lower() townlist.append(town) print(insertion_sort(townlist))