From e1be7d9d734149c9bdfa6525a98d8651731ce5fa Mon Sep 17 00:00:00 2001 From: Pawel Felcyn Date: Mon, 11 Dec 2023 14:16:28 +0100 Subject: [PATCH] d02 --- TaskD01/run.py | 2 +- TaskD01/simple.in | 2 +- TaskD02/run.py | 19 +++++++++++++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 TaskD02/run.py diff --git a/TaskD01/run.py b/TaskD01/run.py index cfcc688..452bf43 100644 --- a/TaskD01/run.py +++ b/TaskD01/run.py @@ -6,7 +6,7 @@ def find_hamlet_lines(file_path): lines = file.readlines() hamlet_lines = [] - pattern = re.compile(r'\bHamlet\b') + pattern = re.compile(r'Hamlet') for _, line in enumerate(lines, start=1): if re.search(pattern, line): diff --git a/TaskD01/simple.in b/TaskD01/simple.in index 3d2b578..7ddd723 100644 --- a/TaskD01/simple.in +++ b/TaskD01/simple.in @@ -1,3 +1,3 @@ -Here comes Hamlet +Here comesHamlet ABC Hamlet Hamlet again diff --git a/TaskD02/run.py b/TaskD02/run.py new file mode 100644 index 0000000..cd81363 --- /dev/null +++ b/TaskD02/run.py @@ -0,0 +1,19 @@ +import re +import os + +def find_pies_lines(file_path): + with open(file_path, 'r') as file: + lines = file.readlines() + + pies_lines = [] + pattern = re.compile(r'\b[pP][iI][eE][sS]\b') + + for _, line in enumerate(lines, start=1): + if re.search(pattern, line): + pies_lines.append(line) + + return pies_lines + +path = os.path.join(os.path.dirname(__file__), 'simple.in') +lines = find_pies_lines(path) +print(lines) \ No newline at end of file