So let's say I have a text file, which contains this:
a
b
c
d
e
I want to iterate through every line of this file, but in the process also get the line following the first line. I have tried this:
with open(txt_file, "r") as f:
for line1, line2 in itertools.zip_longest(*[f] * 2):
if line2 != None:
print(line1.rstrip() + line2.rstrip())
else:
print(line1.rstrip())
which returns something like:
ab
cd
e
However, I would like to have output like this:
ab
bc
cd
de
e
Anyone have an idea for how to accomplish this? Thanks in advance!