I have a text file with 4 different articles containing words in it, each article is separated by the text "<NEW ARTICLE>"
:
<NEW ARTICLE>
Take a look at
what I found.
<NEW ARTICLE>
It looks like something
dark and shiny.
<NEW ARTICLE>
But how can something be dark
and shiny at the same time?
<NEW ARTICLE>
I have no idea.
What I want to do is read this file and turn it into a dictionary, and then keep count of how many times "<NEW ARTICLE>" or "ARTICLE>"
is used. That way when I search for the words "dark and shiny"
it goes to the 2nd and 3rd time "<NEW ARTICLE>"
appears.
The word to search for will be a user inputted variable, and I think I can figure out how to search for it in the file, I'm just having trouble figuring out how to turn the contents of the file into a dictionary and then keeping count everytime "<NEW ARTICLE>" or "ARTICLE>"
appears so that when a user searches for a word in the file, it displays the number of the article in which the word the exists (can be multiple instances of the word in multiple articles).
The output would look something like this:
Input - Word(s) to search for: dark and shiny
Output - Word(s) found in articles: 2 3
Input - Read which article?: 2
Output - It looks like something dark and shiny.
Using Python 3, thanks.