I’m trying to find a way to use one list to filter out elements of another.
Kinda like the intersect syntax but the exact opposite
JavaScript
x
4
1
lst = [0,1,2,6]
2
3
secondlst = [0,1,2,3,4,5,6]
4
expected outcome
JavaScript
1
2
1
[3,4,5]
2
Advertisement
Answer
Simple way:
JavaScript
1
2
1
r = [v for v in secondlst if v not in lst]
2
or
JavaScript
1
2
1
list(set(secondlst).difference(lst))
2