mash4t
0
Q:

how to compare two lists element by element in python and return matched element

list1 = [1, 2, 4]
list2 = [4, 5, 6]

set_difference = set(list1) - set(list2)
list_difference = list(set_difference)

print(list_difference)

#result
[1,2]
1
>>> [i for i, j in zip(a, b) if i == j]
[5]
0

New to Communities?

Join the community