33 lines
933 B
Python
33 lines
933 B
Python
|
import sys
|
||
|
import re2
|
||
|
import csv
|
||
|
|
||
|
def load_surnames_from_csv(filename):
|
||
|
with open(filename, 'r', encoding='utf-8') as csvfile:
|
||
|
reader = csv.reader(csvfile)
|
||
|
surnames = [row[0].strip().lower() for row in reader]
|
||
|
return surnames
|
||
|
|
||
|
def build_patterns(surnames):
|
||
|
patterns = [re2.compile(surname) for surname in surnames]
|
||
|
return patterns
|
||
|
|
||
|
def contains_lowercase_surname(line, patterns):
|
||
|
lowercase_line = line.lower()
|
||
|
return any(pattern.search(lowercase_line) for pattern in patterns)
|
||
|
|
||
|
def main():
|
||
|
male_surnames = load_surnames_from_csv('TaskG00/male_surnames.csv')
|
||
|
female_surnames = load_surnames_from_csv('TaskG00/female_surnames.csv')
|
||
|
|
||
|
all_surnames = list(set(female_surnames + male_surnames))
|
||
|
all_surnames.sort()
|
||
|
patterns = build_patterns(all_surnames)
|
||
|
|
||
|
for line in sys.stdin:
|
||
|
if contains_lowercase_surname(line, patterns):
|
||
|
print(line, end="")
|
||
|
|
||
|
|
||
|
main()
|