I have a list with countries: countries = ['United States', 'Canada', 'France', 'Japan', 'Turkey', 'Germany', 'Ghana', 'Hong Kong', 'United Kingdom']
I want to get all rows that do not contain any country. this is my code:
with open('file.txt') as f:
lines = f.readlines()[1:5]
a = [line.split(':') for line in lines]
for country in countries:
for line in a:
if country not in line:
print(line)
print (line) prints all lines instead of printing those that do not contain countries
source
share