From 6f56d563d44c1eea3218a1ec90d4505b43654242 Mon Sep 17 00:00:00 2001 From: Pawel Felcyn Date: Mon, 11 Dec 2023 14:07:25 +0100 Subject: [PATCH] d01 --- TaskD01/run.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 TaskD01/run.py diff --git a/TaskD01/run.py b/TaskD01/run.py new file mode 100644 index 0000000..cfcc688 --- /dev/null +++ b/TaskD01/run.py @@ -0,0 +1,19 @@ +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) \ No newline at end of file