import re def analizuj_wiersze(plik): with open(plik, 'r', encoding='utf-8') as file: for line in file: line = line.rstrip() regex = r'^([A-ZĆŁÓŚŹŻ][a-ząćęłńóśźż]*a)\s([A-ZĆŁÓŚŹŻ][a-ząćęłńóśźż]{1,})$' match = re.match(regex, line) if match: imie, nazwisko = match.groups() if not re.match(r'^(Kosma|Jarema)$', imie): print(nazwisko) else: print("") else: print("") analizuj_wiersze("test.in")