comparing lists of tuples I have the following code, comparing two lists that contains equally structured tuples:
list_one = [('id_01','aaa','bbb'), ('id_02','aaa','bbb'), ('id_03','aaa','bbb'), ('id_04','aab','bbc')]
list_two = [('id_01','aaa','bbb'), ('id_02','aaa','bbb'), ('id_03','aad','bbd')]

for tupl in list_one:
    for tup in list_two:
        if tupl[0] == tup[0] and (tupl[1] != tup[1] or tupl[2] != tup[2]):
                print(&quot;There is a difference on &quot;+
                      &quot;{} between the two lists&quot;.format(tup[0]))

this code would print
There is a difference on id_03 between the two lists
which is the expected result.
But I wonder if there is a better way to achieve the same result, maybe whitout iterating through list_two for every item of list_one, but any suggestion will be appreciated.
I think you would be better off using set. It provides features like set difference by itself, thereby reducing a lot of work at your end:
set_one = set([('id_01','aaa','bbb'), ('id_02','aaa','bbb'), ('id_03','aaa','bbb'), ('id_04','aab','bbc')])
set_two = set([('id_01','aaa','bbb'), ('id_02','aaa','bbb'), ('id_03','aad','bbd')])
for difference in (set_two - set_one):
    print(f&quot;There is a difference on {difference[0]} between the two lists&quot;)