import re def replace(file_path): word_pattern = r'\b\w+\b' with open(file_path, 'r', encoding='utf-8') as file: for line in file: words = list(re.finditer(word_pattern, line)) if len(words) >= 3: start, end = words[2].span() word_length = end - start line = line[:start] + 'x' * word_length + line[end:] print(line, end='') file_path = 'TaskF05/simple.in' replace(file_path)