I have the following script:
iterator = iter(f.splitlines())
for line in iterator:
if "some_string" in line:
next_line = next(iterator) # next line has some float/integer values
if next_line == "some_value":
do-something
I am opening a file and looking for a keywords in it. If I find them, I append the integer/float value that comes in the next line to a list.
The problem is that the "for" loop will take the line that comes after "next_line". For example:
line1: "keyword"
line2: 3
line3: something-else
line4: keyword
line5: 4
if I found what I want in line1 and took the ineger from line2, "for-loop" will continue from line 3. How can make it continue from the last place that line1 was (continue from line2 regardless that next_line took it)? I want to go one line back.