# https://stackoverflow.com/questions/67201535/how-to-check-txt-file-for-content/67201696#67201664
import re

def extract_country_code(line):
	pattern = re.compile(r'^\.(\w{2})\s')
	m = pattern.match(line)
	if m:
		return m.group(1)

lines = ['.ad ', '', '.country', '.ae ']
for line in lines:
	country = extract_country_code(line)
	if (country):
		print(country)

# the one-line pythonic summary: list comprehension
countries = [c for c in (extract_country_code(line) for line in lines) if c is not None]
print('found ' + str(len(countries)) + ' country-codes ' + str(countries))
