Supposed i have to read a file (quite big, about 20.000 lines). I have to loop through the lines and look for a keyword e.g. STACKOVERFLOW
. Once the keyword is found, i know that i will have to process the next 10 lines.
Currently i am doing like:
with open(filepath) as f:
for line_idx, line in enumerate(f):
if re.match(my_keyword, line):
# do something here from line_idx to line_idx + 9
# can i jump directly to line_idx + 10 ???
Is there a way to skip the process (loop + search) for the next 10 lines when the keyword is found and continue to loop and search at e.g. line_index + 10 further?
Thank you!
UPDATE
I would like to add that what i wanted is a way which i don't have to temporarily save the file into a list. With this method i had a solution of myself already.