keywords = ("banana", "apple", "orange", ...)
before = 50
after = 100
TEXT = "a big text string, i.e., a page of a book"
for k in keywords:
if k in TEXT:
#cut = portion of text starting 'beforeText' chars before occurrence of 'k' and ending 'afterText' chars after occurrence of 'k'
#finalcut = 'cut' with first and last WORDS trimmed to assure starting words are not cut in the middle
Guys, could you help me coding cut
and finalcut
string variables in the above example?
What is the most efficient solution considering I'm dealing with big texts, numerous pages and maybe more than 20 keywords to search?