Find difference in list with identical values
<p>I need to be able to find differences in list that may have identical values to one another besides two added elements</p>

<p>example</p>

<pre><code>a = ['cool task', 'b', 'another task', 'j', 'better task', 'y']
b = ['cool task', 'b', 'a task', 'j', 'another task', 'j', 'better task', 'y']
</code></pre>

<p>How my problem is, both <code>'a task'</code> and <code>'another task'</code> both are followed by a <code>'j'</code></p>

<pre><code>[x for x in b if x not in a]
['a task']
</code></pre>

<p>Because both <code>a</code> and <code>b</code> contain <code>'j'</code>, it is removed from the list.</p>

<p>How would I make so that I end up with </p>

<pre><code>['a task', 'j']
</code></pre>

<p>Depending on your purposes, you could possibly use <code>Counter</code> from the <a href="https://docs.python.org/3.6/library/collections.html" rel="nofollow">collections module</a>:</p>

<pre><code>&gt;&gt;&gt; from collections import Counter
&gt;&gt;&gt; a = Counter(['cool task', 'b', 'another task', 'j', 'better task', 'y'])
&gt;&gt;&gt; b = Counter(['cool task', 'b', 'a task', 'j', 'another task', 'j', 'better task', 'y'])
&gt;&gt;&gt; b-a
Counter({'j': 1, 'a task': 1})
&gt;&gt;&gt; list((b-a).keys())
['j', 'a task']
</code></pre>

python