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 8750931
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:57:07+00:00 2026-06-13T12:57:07+00:00

I am trying to create a program that will search through articles that I

  • 0

I am trying to create a program that will search through articles that I have in a separate document. I am having trouble getting getting my program to search for the term and allow me to view the documents that contain only the search term. Ideally I want the search input to be something like moon, and allow me to access that document. The full document looks like this, and my code follows.

<NEW DOCUMENT>
Look on the bright 
side of Life.
<NEW DOCUMENT>
look on the very, dark
side of the Moon
<NEW DOCUMENT>
is there life
on the moon



search = input("Enter search words: ")
docs = []
document = []
doc_search = []

for line in file2:
    line = line.strip()
    if line == "<NEW DOCUMENT>":
        # start a new document
        document = []
        docs.append(document)
    else:
        # append to the current one
        document.append(line)
docs = ['\n'.join(document) for document in docs]

for line in docs:
    if line == search:
        doc_search = []
        doc_search.append(docs)
  • 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-13T12:57:08+00:00Added an answer on June 13, 2026 at 12:57 pm

    something like this:

    docs=[]
    with open("data1.txt") as f:
        lines=f.read().split("<NEW DOCUMENT>")[1:]
        for x in lines:
            docs.append(x.strip())
        print (docs)
    search = input("Enter search words: ")   
    for x in docs:
        if search in x:
            print ("{} found in:\t {}".format(search,x))
    

    output:

    ['Look on the bright \nside of Life.', 'look on the very, dark\nside of the Moon', 'is there life\non the moon']
    Enter search words: dark
    dark found in:   look on the very, dark
    side of the Moon
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a program that will go through a bunch of tumblr
I have been trying to create a program using perl www::Mechanize that will follow
I have been trying to create a Ruby program that will be running online
I am trying to create a program that will get data directly from socket
I am trying to create a program that will be passed input data from
I am trying to create a program that will do some simple calculations, but
I have a small program that I'm trying to create to get ip addresses
I'm trying to create a program that will allow me to input shorthand names
I'm trying to create a program that will concatenate (add two lists of integers
I'm trying to create a program that will return a certain number decomposed to

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.