''' DS2000 Spring 2023 Sample code from class -- coffee related! ''' DUNKS_FILE = "DD_US.csv" CITY_COL = 2 def read_csv(filename): ''' Function: read_csv Parameters: string Returns: 2d list of strings Does: open the given filename and create a 2d list ''' lst = [] with open(filename, "r") as infile: infile.readline() for line in infile: row = line.split(",") lst.append(row) return lst def get_local(lst, city, col): ''' Function: get_local Parameters: 2d list of strings, city name, city col Returns: 2d list of strings Does: Look for city name in each city col of a given row, and returns a filtered version of the list ''' smaller = [] for row in lst: if city in row[col]: smaller.append(row) return smaller def main(): # Gather data - read in DD locations data = read_csv(DUNKS_FILE) # Gather data - which city? city = input("Which city to look for?\n") # Computation - get all the locations for that city results = get_local(data, city, CITY_COL) # Communiation - print the results print(results) print("\nThere are", len(results), "locations in your city") main()