Q:

How to place every word in a list as an entry in the dictionary

I have a List of multiple documents. so for example 
List = ["today is a beautiful day","tomorrow is rainy day"]

today is a beautiful day is the first document
tomorrow is rainy day is the second document
What I need to do is to look up search terms, so if I look up "beautiful" I will get 0, for the first document, If I look up day, I should get 0 and 1, since both have the word day in them.  I am going to use a dictionary for this purpose. Each entry in the dictionary should have a word as the key and the word’s value as the set of documents that this word appears in. This arrangement allows me to look up a keyword in the dictionary and immediately get all the documents that it appears in, making it easy to figure out documents that might meet a search query.
This is what I have so far, I am not sure how to place every word in a list as an entry in the dictionary:
def searchList(documentNum):
    with open("ap_docs.txt", 'r') as myfile:
        list = [item.strip() for item in myfile.read().split('<NEW DOCUMENT>') if item]
        print(list[documentNum])

print("1-Search for documents")
print("2- Read Document")
print("3-Quit Program")
choice = input("What would you like to do ?")

if choice == '1':
    with open("ap_docs2.txt", 'r') as myfile:
        List = [item.strip() for item in myfile.read().split('<NEW DOCUMENT>') if item]
    from collections import defaultdict   

    d = defaultdict(set)

    for doc_no, doc in enumerate(List):
        for line in doc:
            for word in line.strip().split():
                d[word].update([doc_no])
    print(d['moon'])

if choice == '2':
    documentNum = int(input("What is the document number ?"))
    searchList(documentNum)

if choice == '3':
    exit()

In effect I am trying to make an Inverted Index in Python with the help of a dictionary.

A:

Not very clear what you want to do, and how, but you could use defaultdict and set (if i understand you correctly). For example:
# mockup of lines read from two documents
doc_lines_1 = ["today is a beautiful day", "tomorrow is rainy day"]
doc_lines_2 = ["tomorrow is rainy day is the second document"]

# a list containing your documents
doc_list = [doc_lines_1, doc_lines_2]

from collections import defaultdict   

d = defaultdict(set)

for doc_no, doc in enumerate(doc_list):
    for line in doc:
        for word in line.strip().split():
            d[word].update([doc_no])

print(d['day'])     # {0, 1} "day" in both document 0 and 1           
print(d['rainy'])   # {0, 1} "rainy" in both document 0 and 1      
print(d['second'])  # {1}    "second" only in document 1  

p.s.
DON'T use list as a variable name. You are overwriting build in list type.

