title: Python Compare Tokenized Lists
body: <p>I need the fastest-possible solution to this problem as it will be applied to a huge data set:</p>
  
  <p>Given this master list:</p>
  
  <pre><code>m=['abc','bcd','cde','def']
  </code></pre>
  
  <p>...and this reference list of lists:</p>
  
  <pre><code>r=[['abc','def'],['bcd','cde'],['abc','def','bcd']]
  </code></pre>
  
  <p>I'd like to compare each list within r to the master list (m) and generate a new list of lists. This new object will have a 1 for matches based on the order in m and 0 for non-matches. So the new object (list of lists) will always have the lists of the same length as m.
  Here's what I would expect based on m and r above:</p>
  
  <pre><code>[[1,0,0,1],[0,1,1,0],[1,1,0,1]]
  </code></pre>
  
  <p>Because the first element of r is <code>['abc','def']</code> and has a match
  with the 1st and 4th elements of m, the result is then <code>[1,0,0,1]</code>.</p>
  
  <p>Here's my approach so far (probably way too slow and is missing zeros):</p>
  
  <pre><code>output=[]
  for i in r:
      output.append([1 for x in m if x in i])
  </code></pre>
  
  <p>resulting in:</p>
  
  <pre><code>[[1, 1], [1, 1], [1, 1, 1]]
  </code></pre>
  
  <p>Thanks in advance!</p>