title: Python - Compare Two Lists - Print Result
body: <p>I am trying to create a script that will</p>
  
  <ul>
  <li>look at each word in a text document and store in a list (WordList)</li>
  <li>Look at a second text document and store each word in a list (RandomText)</li>
  <li>Print out the words that appear in both lists</li>
  </ul>
  
  <p>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. </p>
  
  <pre><code>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)
  </code></pre>
  
  <p>Output: </p>
  
  <pre><code>C:\Scripts&gt;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.']
  &lt;function Check at 0x00A9B618&gt;
  </code></pre>