I have a file where only specific "chunks" of lines are needed to be modified, in this case I want to retrieve lines between a and b including those lines as well:
1
2 a
3
4 b
5
6
7 a
8
9
10 b
Now i have a list of tuples which indicates in between which line indexes I need to modify the content: [(2, 4), (7, 10)].
Now I need to replace the content of those lines, so something like
with open("file.txt") as file1:
for index, line in enumerate(log, start=1):
if index in range(**OF ONE OF THE TUPLES IN THE LIST**):
line = ....
I don't understand how to achieve this without having nested loops and duplicating stuff/opening the file multiple times.
Thoughts?