From 348556373ef088a7cf72d46f413be2e68094c213 Mon Sep 17 00:00:00 2001 From: Robert Date: Mon, 25 Nov 2024 12:14:04 +0100 Subject: [PATCH] task1 optimalization --- TaskB01/task1.py | 3 ++- TaskB02/task2.py | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/TaskB01/task1.py b/TaskB01/task1.py index e636911..b5a6746 100644 --- a/TaskB01/task1.py +++ b/TaskB01/task1.py @@ -2,8 +2,9 @@ import regex as re with open('shakespeare.in', encoding='utf8') as file: lines = file.readlines() + pattern = re.compile(r'Hamlet') for line in lines: line = line.strip() - x = re.search(r'Hamlet', line) + x = re.search(pattern, line) if x: print(line) \ No newline at end of file diff --git a/TaskB02/task2.py b/TaskB02/task2.py index e69de29..1cd5442 100644 --- a/TaskB02/task2.py +++ b/TaskB02/task2.py @@ -0,0 +1,7 @@ +import regex as re + +with open('simple.in', encoding='utf8') as file: + lines = file.readlines() + for line in lines: + line = line.strip() + print(line) \ No newline at end of file