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("There is a difference on "+
"{} between the two lists".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.
id_03
were the same in both lists what output would you expect? \$\endgroup\$