More efficient way to remove items from large data sets
<p>I have two large lists:</p>

<pre><code>a = [['abcdefghijklmno', 'foo', 'bar'], … ]
b = [['abcdefghij12345', 'foo', 'bar'], … ]
</code></pre>

<p>I'm interested in all members of <code>a</code> which don't have a corresponding entry in <code>b</code>, and vice versa, based on comparing <code>a[n][0]</code> and <code>b[n][0]</code> for all <em>n</em> in <code>a</code> and <code>b</code>. I create two sets of these sublist items, which allows me to do <code>set_a.difference(set_b)</code>, and vice versa, which is very fast. But creating two lists based on the remaining items in <code>a</code> and <code>b</code> is (perhaps obviously) slower:</p>

<pre><code>def remaining(ls ,y, z):
    return [i for i in ls if i[0] in y.difference(z)]
</code></pre>

<p>where <code>ls</code> is either <code>a</code> or <code>b</code>, and <code>y</code> and <code>z</code> are the two sets detailed above. Is there any point in rethinking the structure of <code>a</code> and <code>b</code> to speed this up (e.g. using dicts with <code>a[0]</code> and <code>b[0]</code> values as the keys?</p>
