Compare commits

...

3 Commits

Author SHA1 Message Date
Pawel Felcyn
f3924b4961 d04 2023-12-11 14:31:09 +01:00
Pawel Felcyn
c40716abe8 d03 2023-12-11 14:23:02 +01:00
Pawel Felcyn
e1be7d9d73 d02 2023-12-11 14:16:28 +01:00
5 changed files with 55 additions and 3 deletions

View File

@ -2,11 +2,11 @@ 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 = []
pattern = re.compile(r'\bHamlet\b')
pattern = re.compile(r'Hamlet')
for _, line in enumerate(lines, start=1):
if re.search(pattern, line):

View File

@ -1,3 +1,3 @@
Here comes Hamlet
Here comesHamlet
ABC
Hamlet Hamlet again

19
TaskD02/run.py Normal file
View File

@ -0,0 +1,19 @@
import re
import os
def find_pies_lines(file_path):
with open(file_path, 'r', encoding='utf-8') 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)

19
TaskD03/run.py Normal file
View File

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

14
TaskD04/run.py Normal file
View File

@ -0,0 +1,14 @@
import re
import os
def find_digits(file_path):
with open(file_path, 'r', encoding='utf-8') as file:
txt = file.read()
pattern = re.compile(r'\d+')
return pattern.findall(txt)
path = os.path.join(os.path.dirname(__file__), 'simple.in')
matches = find_digits(path)
print(matches)