if I have file with words in order in which they were saved, new line comes from below
word 1
word 2
word 3
word 4
word 5
now if I have some word, for example "word 3", if "word 3" exist in text file, show me previous or next word from "word 3" in list order.
data = open('D:\path\file.txt', "r")
searchlines = data.readlines()
for q_numb, line in enumerate(searchlines):
if ('word 3') in line:
for l in searchlines:
prev_line = l[:+1]
print ('"word 3" found:',line, 'previous of "word 3" is:',prev_line)
break
data.close()
my result, but wrong, previous must be "word 2"
"word 3" found: word 3
previous of "word 3" is: word 1
and how go with plus, if I want next word after current?
my result with plus:
"word 3" found: word 3
previous of "word 3" is: w
what I'm doing wrong?