From 71e2825c81373b51b948ddf3ba194c3d2d1afc9f Mon Sep 17 00:00:00 2001 From: HOME-VM-TOSCHOOL Date: Sun, 10 Dec 2023 17:32:26 +0100 Subject: [PATCH] Task D02 --- TaskD02/run.py | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 TaskD02/run.py diff --git a/TaskD02/run.py b/TaskD02/run.py new file mode 100644 index 0000000..9a56f9e --- /dev/null +++ b/TaskD02/run.py @@ -0,0 +1,39 @@ +import re + +file_name: str = "simple" + + +def find_pies_lines(text: str) -> list[str]: + # Define the regular expression pattern + pattern = re.compile(r"\bpies\b", re.IGNORECASE) + + # Split the text into lines + lines = text.split("\n") + + # Use the regular expression to find lines containing "pies" + pies_lines = [ + line for _, line in enumerate(lines, start=1) if re.search(pattern, line) + ] + + return pies_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_pies_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")