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>I think you just want to create a set of the first elements of list2, if you're only looking to compare the first element of the lists.</p>

<pre><code>newlist = []
list2_keys = set(elem[0] for elem in list2)
for entry in list1:
    if entry[0] not in list2_keys:
        newlist.append(entry)
</code></pre>

python list nested