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)