From 3ece1327381688fdaa7707dc7b92706633cfeb4c Mon Sep 17 00:00:00 2001 From: HOME-VM-TOSCHOOL Date: Sun, 10 Dec 2023 17:55:24 +0100 Subject: [PATCH] Task D04 --- TaskD04/run.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 TaskD04/run.py diff --git a/TaskD04/run.py b/TaskD04/run.py new file mode 100644 index 0000000..74eff79 --- /dev/null +++ b/TaskD04/run.py @@ -0,0 +1,33 @@ +import re + +file_name: str = "simple" + + +def find_maximum_digit_substrings(text): + pattern = re.compile(r"\d+") + + matches = pattern.findall(text) + + result = " ".join(matches) + return result + + +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_maximum_digit_substrings(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")