Difference between lists
This method finds the difference between two iterables by keeping only the values that are in the first one.
Python: 3.0    Fatos Morina    03 Jul 2021   0
Login to upvote
1
2
3
4
5
6
7
8
def difference(a, b):
    set_a = set(a)
    set_b = set(b)
    comparison = set_a.difference(set_b)
    return list(comparison)


difference([1,2,3], [1,2,4]) # [3]
Copy | Download as: .py file   PNG
Share on: FB   Twitter   LinkedIn   WA
©2021 - code108labs   Contributors   Hosted on DigitalOcean   Partner website: pythoncircle.com