Small adjustments
This commit is contained in:
parent
5f91662b8e
commit
4d992a3879
@ -1,5 +1,4 @@
|
|||||||
import os
|
import os
|
||||||
import time
|
|
||||||
|
|
||||||
|
|
||||||
NUMBER_OF_INVOICES = 10
|
NUMBER_OF_INVOICES = 10
|
||||||
@ -14,30 +13,18 @@ def join_path(filename: str) -> str:
|
|||||||
with open(join_path("shakespeare.in"), "r", newline="", encoding="utf8") as file:
|
with open(join_path("shakespeare.in"), "r", newline="", encoding="utf8") as file:
|
||||||
text = file.readlines()
|
text = file.readlines()
|
||||||
|
|
||||||
start_time = time.time()
|
|
||||||
found = True
|
found = True
|
||||||
hamlet_array_slow = []
|
hamlet_array_slow = []
|
||||||
for ind, line in enumerate(text):
|
for ind, line in enumerate(text):
|
||||||
for i in range(len(line)):
|
for i in range(len(line)):
|
||||||
found = True
|
found = True
|
||||||
for j in range(len(HAMLET)):
|
for j in range(len(HAMLET)):
|
||||||
if line[i + j] != HAMLET[j] and line[i + j] != HAMLET[j].capitalize():
|
if line[i + j] != HAMLET[j]:
|
||||||
found = False
|
found = False
|
||||||
break
|
break
|
||||||
if found:
|
if found:
|
||||||
# print(ind + 1, ":", line[i:], end="")
|
print(ind + 1, ":", line, end="")
|
||||||
hamlet_array_slow.append(ind + 1)
|
hamlet_array_slow.append(ind + 1)
|
||||||
break
|
break
|
||||||
|
# print(len(phrase_array_slow))
|
||||||
# print(*hamlet_array_slow, sep="\n")
|
|
||||||
|
|
||||||
print(time.time() - start_time)
|
|
||||||
|
|
||||||
# time this function
|
|
||||||
|
|
||||||
start_time = time.time()
|
|
||||||
hamlet_array_fast = []
|
|
||||||
for ind, line in enumerate(text):
|
|
||||||
if HAMLET in line:
|
|
||||||
hamlet_array_fast.append(ind + 1)
|
|
||||||
print(time.time() - start_time)
|
|
||||||
|
@ -44,8 +44,7 @@ for ind, line in enumerate(text):
|
|||||||
found = find_me()
|
found = find_me()
|
||||||
|
|
||||||
if found:
|
if found:
|
||||||
print(ind + 1, ":", line[i:], end="")
|
print(ind + 1, ":", line, end="")
|
||||||
phrase_array_slow.append(ind + 1)
|
phrase_array_slow.append(ind + 1)
|
||||||
break
|
break
|
||||||
|
# print(len(phrase_array_slow))
|
||||||
# print(*phrase_array_slow, sep="\n")
|
|
||||||
|
File diff suppressed because one or more lines are too long
@ -1,5 +1,4 @@
|
|||||||
import os
|
import os
|
||||||
from sre_parse import DIGITS
|
|
||||||
|
|
||||||
|
|
||||||
NUMBER_OF_INVOICES = 10
|
NUMBER_OF_INVOICES = 10
|
||||||
@ -12,7 +11,9 @@ def join_path(filename: str) -> str:
|
|||||||
return os.path.join(DIR, filename)
|
return os.path.join(DIR, filename)
|
||||||
|
|
||||||
|
|
||||||
with open(join_path("simple.in"), "r", newline="", encoding="utf8") as file:
|
with open(
|
||||||
|
join_path("polish_wiki_excerpt.in"), "r", newline="", encoding="utf8"
|
||||||
|
) as file:
|
||||||
text = file.readlines()
|
text = file.readlines()
|
||||||
|
|
||||||
|
|
||||||
@ -42,16 +43,7 @@ for ind, line in enumerate(text):
|
|||||||
found = find_me()
|
found = find_me()
|
||||||
|
|
||||||
if found:
|
if found:
|
||||||
# print(ind + 1, ":", line[i:], end="")
|
print(ind + 1, ":", line, end="")
|
||||||
phrase_array_slow.append(ind + 1)
|
phrase_array_slow.append(ind + 1)
|
||||||
break
|
break
|
||||||
|
# print(len(phrase_array_slow))
|
||||||
|
|
||||||
# show numbers that are not in phrase_array and in rage of len(phrase_array_slow)
|
|
||||||
not_in_phrase_array = [
|
|
||||||
num for num in range(1, len(phrase_array_slow) + 1) if num not in phrase_array_slow
|
|
||||||
]
|
|
||||||
print(*not_in_phrase_array, sep="\n")
|
|
||||||
|
|
||||||
|
|
||||||
# print(*phrase_array_slow, sep="\n")
|
|
||||||
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user