jfz-2023-s473555/TaskA02/run.py

51 lines
1.0 KiB
Python
Raw Normal View History

2023-10-16 13:23:32 +02:00
import os
NUMBER_OF_INVOICES = 10
DIR = os.path.dirname(__file__)
PHRASE = "pies"
def join_path(filename: str) -> str:
return os.path.join(DIR, filename)
2023-10-17 04:21:48 +02:00
with open(
join_path("polish_wiki_excerpt.in"), "r", newline="", encoding="utf8"
) as file:
2023-10-16 13:23:32 +02:00
text = file.readlines()
2023-10-17 04:21:48 +02:00
def not_in(letter, set):
for i in set:
if i == letter:
return False
return True
2023-10-16 13:23:32 +02:00
def find_me():
for j in range(len(PHRASE)):
if line[i + j] != PHRASE[j] and line[i + j] != PHRASE[j].capitalize():
return False
2023-10-17 04:21:48 +02:00
if not_in(line[i - 1], [" ", "\n"]):
2023-10-16 13:23:32 +02:00
return False
2023-10-17 04:21:48 +02:00
if not_in(line[i + len(PHRASE)], [" ", "\n", "\r"]):
2023-10-16 13:23:32 +02:00
return False
return True
found = True
phrase_array_slow = []
for ind, line in enumerate(text):
for i in range(len(line)):
found = True
found = find_me()
if found:
2023-10-21 02:07:06 +02:00
print(ind + 1, ":", line, end="")
2023-10-16 13:23:32 +02:00
phrase_array_slow.append(ind + 1)
break
2023-10-21 02:07:06 +02:00
# print(len(phrase_array_slow))