Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8743203
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:38:04+00:00 2026-06-13T11:38:04+00:00

I have a text file with 4 different articles containing words in it, each

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T11:38:05+00:00Added an answer on June 13, 2026 at 11:38 am

    This question sounds like homework to me. So I will give you an algorithm and let you implement it yourself:

    1. Create an empty dictionary
    2. Maintain an integer (lets call it articleNum). Start it at 0.
    3. Iterate through the input file (open it for reading first, preferably using with)
    4. If the line you see contains <NEW ARTICLE>, then increment articleNum.
    5. Else, iterate through the words in the line (use line.split())
    6. For each word in the line, check if that word is a key in the dictionary
    7. If it is not already a key in the dictionary, add it as a key to the dictionary and make it’s value a list, that contains the value of articleNum
    8. If it is already a key in the dictionary, then append articleNum to the value of this key
    9. Once you are done reading the file, as the user for input.
    10. Get the value of the user’s input from the dictionary (if the input is already a key in the dictionary); this should be a list of integers
    11. Print out this list of integers to the user, as output

    Hope this helps

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a text file with several different sections. Each section has a header
I have a text file which consists of different lines it looks like Destination|203.190.242.69|reached|203.190.244.6
I have got this text file with latitude and longitude values of different points
I have Text file that contains data separated with a comma , . How
Using VB6 I have the text file with different sizes, so i want to
I have this text file what contains different fields. Some fields may contain binary
I have a text file that looks like this: STUFF UP HERE APEXED NUMBER
I have multiple text file, each is a result of a simulation. The content
Hi I have a text file containing two arrays and one value(all integers) like
Php noob. I have this text file (names.txt) with comma separated names and codes.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.