I am trying to create a script that will
- look at each word in a text document and store in a list (WordList)
- Look at a second text document and store each word in a list (RandomText)
- Print out the words that appear in both lists
I have come up with the below which stores the text in a file, however I can't seem to get the function to compare the lists and print similarities.
KeyWords = open("wordlist.txt").readlines() # Opens WordList text file, Reads each line and stores in a list named "KeyWords".
RanText = open("RandomText.txt").readlines() # Opens RandomText text file, reads each line and stores in a list named "RanText"
def Check():
for x in KeyWords:
if x in RanText:
print(x)
print(KeyWords)
print(RanText)
print(Check)
Output:
C:\Scripts>python Search.py
['Word1\n', 'Word2\n', 'Word3\n', 'Word4\n', 'Word5']
['Lorem ipsum dolor sit amet, Word1 consectetur adipiscing elit. Nunc fringilla arcu congue metus aliquam mollis.\n', 'Mauris nec maximus purus. Maecenas sit amet pretium tellus. Praesent Word3 sed rhoncus eo. Duis id commodo orci.\n', 'Quisque at dignissim lacus.']
<function Check at 0x00A9B618>