task1 optimalization

This commit is contained in:
Robert 2024-11-25 12:14:04 +01:00
parent ed65fd5535
commit 348556373e
2 changed files with 9 additions and 1 deletions

View File

@ -2,8 +2,9 @@ import regex as re
with open('shakespeare.in', encoding='utf8') as file: with open('shakespeare.in', encoding='utf8') as file:
lines = file.readlines() lines = file.readlines()
pattern = re.compile(r'Hamlet')
for line in lines: for line in lines:
line = line.strip() line = line.strip()
x = re.search(r'Hamlet', line) x = re.search(pattern, line)
if x: if x:
print(line) print(line)

View File

@ -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)