''' DS2000 Spring 2023 Sample code from class - reading from a file into a list Anytime we learn a new data structure, we need to know: 1. Create -- lst = [] 2. Add things -- lst.append(item) 3. Look at one thing -- lst[position] 4. Look at ALL the things -- for item in lst: ... ''' HOTSPUR_FILE = "tottenham_results.txt" def main(): # Gather data - create three empty lists and read from the file opponents = [] tot_scores = [] opp_scores = [] with open(HOTSPUR_FILE, "r") as infile: while True: opponent = infile.readline() tot_score = infile.readline() opp_score = infile.readline() # If at end of the file, stop the loop if opponent == "": break # If we get this far, the data in our variables is real! Add them to our lists. opponents.append(opponent.strip()) tot_scores.append(int(tot_score)) opp_scores.append(int(opp_score)) # Look at ONE thing - what was the most recent game? print("Most recently, we played", opponents[0], "and we scored", tot_scores[0]) # Look at ALL the things, all the opponents # in the opponents list for opp in opponents: if opp == "Arsenal": print("BOOOOO") else: print(opp) main()