import re def swap(file_path): pattern = r'\b(?=\w*[a-ząćęłńóśźż])(?=\w*[A-ZĄĆĘŁŃÓŚŹŻ])\w+\b' def swap_case(match): return match.group(0).swapcase() with open(file_path, 'r', encoding='utf-8') as file: for line in file: swapped_line = re.sub(pattern, swap_case, line) print(swapped_line, end='') file_path = 'TaskF01/simple.in' swap(file_path)