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>For <strong>simple list</strong> - what you ask is simply searching for that next item in the list:</p>

<pre><code>&gt;&gt;&gt; a = ['cool task', 'b', 'another task', 'j', 'better task', 'y']
&gt;&gt;&gt; b = ['cool task', 'b', 'a task', 'j', 'another task', 'j', 'better task', 'y']
&gt;&gt;&gt; c = [[x, b[b.index(x) + 1]] for x in b if x not in a]
&gt;&gt;&gt; c
[['a task', 'j']]
</code></pre>

<p>But I think you are actually aiming at using dictionary or tuples.</p>

<p><strong>Tuples:</strong></p>

<pre><code>&gt;&gt;&gt; a = [('cool task', 'b'), ('another task', 'j'), ('better task', 'y')]
&gt;&gt;&gt; b = [('cool task', 'b'), ('a task', 'j'), ('another task', 'j'), ('better task', 'y')]
&gt;&gt;&gt; c = [x for x in b if x not in a]
&gt;&gt;&gt; c
[('a task', 'j')]
</code></pre>

<p><strong>Dictionaries:</strong></p>

<pre><code>&gt;&gt;&gt; a = {'cool task': 'b', 'another task': 'j', 'better task': 'y'}
&gt;&gt;&gt; b = {'cool task': 'b', 'a task': 'j', 'another task': 'j', 'better task': 'y'}
&gt;&gt;&gt; c = [(x, b[x]) for x in b if x not in a]
&gt;&gt;&gt; c
[('a task', 'j')]
</code></pre>

python