From c40716abe801ccf597da7a9c461081fb96bd67b5 Mon Sep 17 00:00:00 2001 From: Pawel Felcyn Date: Mon, 11 Dec 2023 14:23:02 +0100 Subject: [PATCH] d03 --- TaskD01/run.py | 2 +- TaskD02/run.py | 2 +- TaskD03/run.py | 19 +++++++++++++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 TaskD03/run.py diff --git a/TaskD01/run.py b/TaskD01/run.py index 452bf43..36caead 100644 --- a/TaskD01/run.py +++ b/TaskD01/run.py @@ -2,7 +2,7 @@ import re import os def find_hamlet_lines(file_path): - with open(file_path, 'r') as file: + with open(file_path, 'r', encoding='utf-8') as file: lines = file.readlines() hamlet_lines = [] diff --git a/TaskD02/run.py b/TaskD02/run.py index cd81363..57ac933 100644 --- a/TaskD02/run.py +++ b/TaskD02/run.py @@ -2,7 +2,7 @@ import re import os def find_pies_lines(file_path): - with open(file_path, 'r') as file: + with open(file_path, 'r', encoding='utf-8') as file: lines = file.readlines() pies_lines = [] diff --git a/TaskD03/run.py b/TaskD03/run.py new file mode 100644 index 0000000..3953e8e --- /dev/null +++ b/TaskD03/run.py @@ -0,0 +1,19 @@ +import re +import os + +def find_date_lines(file_path): + with open(file_path, 'r', encoding='utf-8') as file: + lines = file.readlines() + + pies_lines = [] + pattern = re.compile(r'19[0-9][0-9] r\.') + + 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_date_lines(path) +print(lines) \ No newline at end of file