mirror of
https://github.com/kristoferssolo/School.git
synced 2025-10-21 20:10:38 +00:00
task 061021 update
This commit is contained in:
parent
e2e6b4c834
commit
5a452e54c2
@ -1,14 +1,14 @@
|
|||||||
# Author - Kristiāns Francis Cagulis
|
# Author - Kristiāns Francis Cagulis
|
||||||
# Date - 06.10.2021
|
# Date - 06.10.2021
|
||||||
|
|
||||||
chapters = 61
|
CHAPTERS = 61
|
||||||
|
|
||||||
|
|
||||||
def read_array():
|
def read_array():
|
||||||
with open('book.txt', encoding='utf-8') as book:
|
with open('book.txt', encoding='utf-8') as book:
|
||||||
lines = [line.strip('\n') for line in book] # removes 'enter' characters
|
lines = [line.strip('\n') for line in book] # removes 'enter' characters
|
||||||
with open('array_output.txt', 'w') as output:
|
with open('array_output.txt', 'w') as output:
|
||||||
for i in range(1, chapters + 1):
|
for i in range(1, CHAPTERS + 1):
|
||||||
line = lines.index(f"Chapter {i}") + 1 # finds all chapter indexes/lines
|
line = lines.index(f"Chapter {i}") + 1 # finds all chapter indexes/lines
|
||||||
output.write(f"Line {line} - Chapter {i}\n") # writes line in file
|
output.write(f"Line {line} - Chapter {i}\n") # writes line in file
|
||||||
|
|
||||||
@ -18,7 +18,7 @@ def read_string():
|
|||||||
with open('book.txt', encoding='utf-8') as book:
|
with open('book.txt', encoding='utf-8') as book:
|
||||||
lines = book.read()
|
lines = book.read()
|
||||||
with open('str_output.txt', 'w') as output:
|
with open('str_output.txt', 'w') as output:
|
||||||
for i in range(1, chapters + 1):
|
for i in range(1, CHAPTERS + 1):
|
||||||
_, position = re.finditer(rf"\bChapter {i}\b", lines) # finds all chapter positions
|
_, position = re.finditer(rf"\bChapter {i}\b", lines) # finds all chapter positions
|
||||||
output.write(f"Position {position.start()} - Chapter {i}\n") # writes position in file
|
output.write(f"Position {position.start()} - Chapter {i}\n") # writes position in file
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user