From 16c8d13f3cc96cf2ec5ad124c0ce53bf02e8535d Mon Sep 17 00:00:00 2001 From: HOME-VM-TOSCHOOL Date: Sun, 10 Dec 2023 17:44:59 +0100 Subject: [PATCH] small rewrites --- TaskD01/run.py | 4 ++-- TaskD02/run.py | 4 +--- TaskD03/run.py | 6 ++---- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/TaskD01/run.py b/TaskD01/run.py index a1ce9d5..d618543 100644 --- a/TaskD01/run.py +++ b/TaskD01/run.py @@ -5,13 +5,13 @@ file_name: str = "simple" def find_hamlet_lines(text: str) -> list[str]: # Define the regular expression pattern - pattern = re.compile(r".*Hamlet.*", re.IGNORECASE) + 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)] + hamlet_lines = [line for line in lines if re.search(pattern, line)] return hamlet_lines diff --git a/TaskD02/run.py b/TaskD02/run.py index 9a56f9e..9a91302 100644 --- a/TaskD02/run.py +++ b/TaskD02/run.py @@ -11,9 +11,7 @@ def find_pies_lines(text: str) -> list[str]: 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) - ] + pies_lines = [line for line in lines if re.search(pattern, line)] return pies_lines diff --git a/TaskD03/run.py b/TaskD03/run.py index 0c7d180..c3883d6 100644 --- a/TaskD03/run.py +++ b/TaskD03/run.py @@ -5,15 +5,13 @@ file_name: str = "simple" def find_dates_1900_to_1999(text): # Define the regular expression pattern - pattern = re.compile(r".*19\d{2} r\..*", re.IGNORECASE) + pattern = re.compile(r"19\d{2} r\.", re.IGNORECASE) # Split the text into lines lines = text.split("\n") # Use the regular expression to find lines containing dates from 1900 to 1999 - date_lines = [ - line for _, line in enumerate(lines, start=1) if re.match(pattern, line) - ] + date_lines = [line for line in lines if re.search(pattern, line)] return date_lines