data = f.readlines() countries = [] # this is the storage list for the countries. An empty list capitals = [] # this one is for the capitals for line in data: line = line.rstrip('\n') country, capital = line.split(',') countries.append(country) # append 'country' to 'countries'. capitals.append(capital) # append 'capital' to 'capitals'Now in the second part of the script, you can't use '==' operator to check if an object is in the list. Line 23. They are different types. One is a string and another list of strings. The way you do it is to use 'in'. Almost plain English.
elif line in countries: