My goal is to remove any non-countries from the list, "Checklist". Obviously "Munster" is not a country. Portugal is though. Why does it get removed then?
checklist = ["Portugal", "Germany", "Munster", "Spain"]
def CheckCountry(i):
with open("C:/Users/Soham/Desktop/Python Exercises/original.txt","r") as f:
for countries in f.readlines():
if countries==i:
continue
else:
return True
return False
for i in checklist:
if CheckCountry(i)==True:
index=checklist.index(i)
checklist.pop(index)
else:
CheckCountry(i)
print(checklist)
Please tell me what is wrong with my code. Keep in mind I have not learned regex or lambda yet.