0

How to find out unique elements of list1 from list2

Let's: l1 = [1,2,3,4,5] l2 = [3,4,5] output should be [1,2]

17th Jul 2020, 8:38 AM
Rahul Anand
Rahul Anand - avatar
3 Réponses
+ 5
Here is a version using set() and difference(): a = [1,2,3,4,5] b = [3,4,5] print(set(a).difference(set(b)))
17th Jul 2020, 10:39 AM
Lothar
Lothar - avatar
+ 2
List comprehension a=[1,2,3,4,5] b=[3,4,5] print([i for i in a if i not in b])
17th Jul 2020, 8:42 AM
Justus
Justus - avatar
+ 1
print( set(l1) - set(l2))
17th Jul 2020, 10:06 AM
Jayakrishna 🇮🇳