Python ProgrammingPython Programming

Compute list difference in Python

list1 = [5, 9, 4, 8, 7, 1]
list2 = [5, 6, 8, 9, 7, 1]

print(set(list1).difference(set(list2)))
print(set(list2).difference(set(list1)))
Output
{4}
{6}