A minimal version of what you want to do based on random data would be:
import random
import loremipsum
text = ' '.join(loremipsum.get_sentences(400)).split() # split into words
# where to replace part with Mr. Darcy
where = [random.randint(1, len(text) - 1) for _ in range(1000)]
for p in where:
text[p] = "Mr. Darcy"
text = ' '.join(text)
chunk_size = 100
# check for chunk_size list elements (some containing "Mr. Darcy" - most not)
# joins each chunk into a text then looks for Mr. Darcy
x = [' '.join(chunk).count('Mr. Darcy') for chunk in (
text[i: i + chunk_size] for i in range(0, len(text), chunk_size))]
print(x)
Output:
[34, 28, 28, 34, 35, 22, 25, 31, 26, 32, 23, 21, 37, 32, 29, 40, 30,
28, 40, 29, 35, 31, 25, 34, 28, 31, 32, 11]
You would need to do
with open("yourfile.txt") as f:
text = f.read().split()
chunk_size = 3000
chunks = [ ' '.join(text[i: i + chunk_size]) for i in range(0, len(text), chunk_size))]
and then count for each chunk in chunks.