title: Python - check for combination of items in list of tuples
body: <p>I have two lists of tuples: The first (A) has the value sets I'm checking. The second (B) has combinations of values that I want to weed out if they're present in A.</p>
  
  <pre><code>A = [(1, 2, 3), (6, 10, 8)]
  B = [(5, 7, 9), (10, 6)]
  </code></pre>
  
  <p>As you can see, the checking is complicated by the facts that:
  - the B tuples may be shorter than the A tuples
  - the B tuples may vary in length
  - the values may appear in a different order in a B tuple than they do in an A tuple
  - the A tuples all have identical length but that length can't be predetermined</p>
  
  <p>The best way I have come up with to do this involves some redundancy:</p>
  
  <pre><code>bad_tuples = [tup for badtup in B for tup in A 
                if [baditem for baditem in badtup if baditem in tup]
                and len([baditem for baditem in badtup if baditem in tup]) == len(badtup)]
  good_tuples = [tup for tup in A if tup not in bad_tuples]
  </code></pre>
  
  <p>I think this gets the job done, but I don't like the fact that I have to duplicate an identical list comprehension in finding bad_tuples. I also find it hard to read and so error-prone. So can anyone think of a more elegant/efficient way of accomplishing the task?</p>
  
  <p>(If it matters, in my application there are likely to be many (but &lt; 100) tuples in A and only a few (&lt; 10) tuples in B.)</p>