From e4500a95f9bbdfb4c09bf9583041096442f1434f Mon Sep 17 00:00:00 2001 From: HOME-VM-TOSCHOOL Date: Sun, 10 Dec 2023 17:21:22 +0100 Subject: [PATCH] Task D01 --- TaskD01/run.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 TaskD01/run.py diff --git a/TaskD01/run.py b/TaskD01/run.py new file mode 100644 index 0000000..a1ce9d5 --- /dev/null +++ b/TaskD01/run.py @@ -0,0 +1,37 @@ +import re + +file_name: str = "simple" + + +def find_hamlet_lines(text: str) -> list[str]: + # Define the regular expression pattern + pattern = re.compile(r".*Hamlet.*", re.IGNORECASE) + + # Split the text into lines + lines = text.split("\n") + + # Use the regular expression to find lines containing "Hamlet" + hamlet_lines = [line for line in lines if re.match(pattern, line)] + + return hamlet_lines + + +with open(file_name + ".in", "r", newline="", encoding="utf8") as file: + text = file.read() + +with open(file_name + ".exp", "r", newline="", encoding="utf8") as file: + expected = [line.rstrip() for line in file.readlines()] + + +found_lines = find_hamlet_lines(text) + +mistake = False +for line in expected: + if line in found_lines: + print(f"{line}") + else: + print(f"NO: {line}") + mistake = True + +if mistake: + print("ERROR")