I am looking for a few words in a file in python. After I find each word, I need to read the next two words from the file. I was looking for some solution, but I could not find the reading of the following words.
# offsetFile - file pointer # searchTerms - list of words for line in offsetFile: for word in searchTerms: if word in line: # here get the next two terms after the word
Thank you for your time.
Update: Only the first appearance is required. In fact, in this case, only one occurrence of this word is possible.
File:
accept 42 2820 access 183 3145 accid 1 4589 algebra 153 16272 algem 4 17439 algol 202 6530
word: ['access', 'algebra']
Finding a file, when I come across "access" and "algebra", I need the values 183 3145 and 153 16272 respectively.
Quazi farhan
source share