Comparing nested list Python
<p>I guess the code will most easily explain what I'm going for...</p>

<pre><code>list1 = [("1", "Item 1"), ("2", "Item 2"), ("3", "Item 3"), ("4", "Item 4")]
list2 = [("1", "Item 1"), ("2", "Item 2"), ("4", "Item 4")]

newlist = []

for i,j in list1:
    if i not in list2[0]:
        entry = (i,j)
        newlist.append(entry)

print(newlist)
</code></pre>

<p>if we call the nested tuples [i][j]</p>

<p>I want to compare the [i] but once this has been done I want to keep the corresponding [j] value. </p>

<p>I have found lots of information regarding nested tuples on the internet but most refer to finding a specific item. </p>

<p>I did recently use an expression below, which worked perfectly, this seems very similar, but it just won't play ball.</p>

<pre><code>for i,j in highscores:
    print("\tPlayer:\t", j, "\tScore: ", i)
</code></pre>

<p>Any help would be much apppreciated. </p>

<p>If I understand correctly from your comment you would like to take as newlist: </p>

<pre><code>newlist = [("3", "Item 3")]
</code></pre>

<p>You can do this using:</p>

<p>1) list comprehension:</p>

<pre><code>newlist = [item for item in list1 if item not in list2]
print newlist
</code></pre>

<p>This will give you as a result:</p>

<pre><code>[('3', 'Item 3')]
</code></pre>

<p>2) You could also use <a href="https://python-reference.readthedocs.io/en/latest/docs/sets/symmetric_difference.html" rel="nofollow">symmetric difference</a> like:</p>

<pre><code>L = set(list1).symmetric_difference(list2)
newlist = list(L)
print newlist
</code></pre>

<p>This will also give you the same result!</p>

<p>3) Finally you can use a lambda function like:</p>

<pre><code>unique = lambda l1, l2: set(l1).difference(l2)
x = unique(list1, list2)
newlist = list(x)
</code></pre>

<p>This will also produce the same result!</p>

<p>4) Oh, and last but not least, using simple set properties:</p>

<pre><code>newlist = list((set(list1)-set(list2)))
</code></pre>

python list nested