In my input file I have many lines, I am searching only one, which meets my requirements. And that's already done. But I need to print a line after this line which has been already found.
Example of input:
line 1 x
line 2 a
line 3 a
line 3 a
I am searching for line where is x
inside.
for lines in input:
if 'x' in lines:
print (lines)
Result: line 1 x
So now I need to show one line after my result
Expected result:
line 1 x
line 2 a
I also tried:
for lines in input:
if 'x' in lines:
print (lines, '\n', lines[lines.index(lines) + 0:100])
Try splitting your input into a list first:
a = input.split('\n')
for lines in a:
if 'x' in lines:
print (lines, '\n', a[a.index(lines) + 1])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With