I am working on a program (Python) which needs to look through a large text file with a bunch of words in it.
The file is around 4.03 MB (over 4 million characters) of words seperated with a new line. (This is what I mean)
What I want to do is look line by line in the file for a specific word then get the "index" of it. Also I want to be able to reach into the file and get a specific word by using the index without looking through the file.
How would I make this happen (preferably a very efficient code since my program will be looking through the file quite frequently)?
By the index, do you mean to position of the word in the file? This will find the position of the specified text in a file...
file = open("text.txt","r") text = file.read() print(text.index("word"))
1.4m articles
1.4m replys
5 comments
57.0k users