title: Inverse Match with Python
body: <p>I've been trying to work with two lists in Python 2.7. I've come part way, but spending some time searching hasn't brought up much in the way of results.</p>
  
  <p><code>List1</code>: Is a list of specific numbers sequences that I was searching within List2. (e.g.) <code>['209583', '185372', '684392', '995423']</code></p>
  
  <p><code>List2</code>: Has a variation of these numbers from list1. (e.g.) <code>['209583_345829', '57185372', '853921864']</code></p>
  
  <p>Now I can match and pull with what I found below... But I was also looking for the inverse; set a variable to all the numbers in <code>List1</code> that are not in <code>List2</code>.</p>
  
  <pre><code>matching = [s for s in list2 if any(xs in s for xs in list1)]
  </code></pre>
  
  <p>So what should be left in a non matching variable would be <code>'995423'</code>. I've tried reworking the code above but I feel like it's right under my nose.</p>
  
  <p>Also, would it not be beneficial to just use an If/Else statement for performance reasons? E.g. If matching do this, else not matching do this... That way it is only running once vs twice. <br/><br/>This is a simple example, but the lists for both could push over 10,000 lines per.<br/><br/>Thanks!</p>