I have a text file that I want to loop through, slice some contents, and store in a separate list. The text file contains:
blu sre
before we start
start the process
blah blah
blah blha
end the process
blah böah
start the process
blah blah
blah blha
end the process
start the process
blah blah
end the process
blah
I want to catch all text between 'start the process'
and 'end the process'
and store in a new list so that each line of the list will contain every text between start the process and end the process.
The desired new list should be like this
list[0] start the process
blah blah
blah blha
end the process
list[1] start the process
blah blah
blah blha
end the process
list[2] start the process
blah blah
end the process
Here is the code I prepared. I don't why its not giving me the required result.
list = []
text = 'start the process'
text2 = 'end the process'
for pattern in range (len(file)):if text in file[pattern]:x = patternif text2 in file[pattern]:y = patternlist[i]= file[x:y]i = i+1