Python way of doing difference of lists containing lists
<p>Consider two lists A and B. I know that <code>list(set(A) - set(B))</code> will give the difference between A and B. What about the situation whereby elements in both A and B are lists. i.e. A and B are list of list? For e.g.</p>

<pre><code>A = [[1,2], [3,4], [5,6]]
B = [[3,4], [7,8]]
</code></pre>

<p>I wish to return the difference <code>A - B</code>  as a list of list i.e. <code>[[1,2],[5,6]]</code></p>

<pre><code>list(set(A) - set(B))
TypeError: unhashable type: 'list'
</code></pre>

<p>The idea is to convert the list of lists to lists of tuples,<br>
which are hashable and are, thus, candidates of making sets themselves:</p>

<pre><code>In [192]: C = set(map(tuple, A)) - set(map(tuple, B))

In [193]: C
Out[193]: {(1, 2), (5, 6)}
</code></pre>

<p>And one more touch:</p>

<pre><code>In [196]: [*map(list, C)]
Out[196]: [[1, 2], [5, 6]]
</code></pre>

<p><strong>ADDED</strong></p>

<p>In python 2.7 the final touch is simpler:</p>

<pre><code>map(list, C)
</code></pre>

python