""" func extractCities() open the file read one line to trash header create empty list for the cities for every additional line in the file split the line to get the city add the city to the list return the list """ def extractCities(): fin = open("IA_population_data.txt","r") fin.readline() #throw away the header line cities = [] for line in fin: data = line.split("\t") city = data[0] cities.append(city) fin.close() return cities """ function lookFor(list of cities, target city) for eachcity in list of cities if eachcity is the targetcity return True return False """ def lookFor(cities,target): for name in cities: if name==target: return True return False """ function lookForBinary(list of cities, target city) record the lowest possible place in the list the city could be (0) record the highest possible place in the list the city could be (len(list)-1) while there are still cities between those numbers: find the middle point consider the city at that middle point look to see if the current city is your goal if it is, return True if it is not, is the goal AFTER the current city? update the lowest possible index to current +1 else update the highest possible index to current-1 When you reach a point where there are no cities left return False """ def lookForBinary(cities,target): low = 0 high = len(cities)-1 while high>=low: average = int((low+high)/2) print(average, cities[average]) if (cities[average].upper()==target.upper()): return True elif (cities[average].upper()target.upper()): high =average-1 return False