jfz-2023-s473616/TaskD01/run.py

19 lines
454 B
Python
Raw Normal View History

2023-12-11 14:07:25 +01:00
import re
import os
def find_hamlet_lines(file_path):
with open(file_path, 'r') as file:
lines = file.readlines()
hamlet_lines = []
pattern = re.compile(r'\bHamlet\b')
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)