How to find difference between two lists in Python?


I have two lists in my code, I want to find the difference between these lists. How can I do that?

Here's an example of what I want.

Example

a = [1,2,3]
b = [2,4,5]
c = [1,3]

1 Answer

4 years ago by

You can do like below, convert lists to sets and find the difference.

a = [1,2,3]
b = [2,4,5]

print(list(set(a)-set(b)))

Check output here

4 years ago by Divya