title: Unittest - Assert a set of items of a list are (or not) contained in another list
body: <p>Hello I am new to programming and and trying to make a test that checks whether <strong>any</strong> items in a list of items are present in another list (using unittest in Python 2.7).</p>
  
  <p>For example if I have a list ["dog", "cat", "frog] and the result of the method I am testing is ["tiger", "lion", "kangaroo", "frog] I want the test to fail because it contains one of the items of the previous list ("frog"). I would also like the test to tell me what words did both lists have (i.e. what words caused the test to be a fail).</p>
  
  <p>I have tried:</p>
  
  <pre><code>self.assertIn(["cat", "dog"], method("cat dog tiger"))
  </code></pre>
  
  <p>The result of the method is ["cat", "dog", "tiger"] yet the result of the test is a fail and says:</p>
  
  <pre><code>AssertionError: ['cat', 'dog'] not found in ['cat', 'dog', 'tiger']
  </code></pre>
  
  <p>I want this test to return ok because 'cat' and 'dog' are present in the second list. It seems assertIn doesn't do what I thought it would do (I thought it was to check if any of <em>a</em> are present in <em>b</em>).</p>
  
  <p>And vice versa, assertNotIn passes when I want it to fail. </p>
  
  <p>I've been searching for a while now but because I'm not sure what I'm looking for which makes it hard to find. </p>
  
  <p>Thank you for reading, I hope that makes sense. </p>
  
  <p><strong>EDIT</strong>: I have gone with Chris's solution and it works as I want:</p>
  
  <pre><code>def myComp(list1, list2):
      section = list(set(list1).intersection(list2))
  </code></pre>
  
  <p>To get the list of words that overlap (i.e. triggering the fail) in the error message, I added the code below from here <a href="https://stackoverflow.com/questions/3807694/how-to-change-the-message-in-a-python-assertionerror">How to change the message in a Python AssertionError?</a>:</p>
  
  <pre><code>try:
      assert(len(section)==0)
  except AssertionError as e:
      e.args += ('The following are present in the processed text', 
      section)
      raise
  </code></pre>
  
  <p>The result is exactly what I want:</p>
  
  <pre><code>AssertionError: ('The following are pressent in the processed text', ['dog', 
  'cat'])
  </code></pre>