jfz-2023-s473616/TaskD01/run.py

19 lines
468 B
Python

import re
import os
def find_hamlet_lines(file_path):
with open(file_path, 'r', encoding='utf-8') as file:
lines = file.readlines()
hamlet_lines = []
pattern = re.compile(r'Hamlet')
for _, line in enumerate(lines, start=1):
if re.search(pattern, line):
hamlet_lines.append(line)
return hamlet_lines
path = os.path.join(os.path.dirname(__file__), 'simple.in')
lines = find_hamlet_lines(path)
print(lines)