I want to subtract two lists and read this question Remove all the elements that occur in one list from another
# a-b
def subb(a,b):
return [i for i in a if i not in b]
print subb([1,2,1,2],[1,2])
But the result is empty list which is not what I want,I think it should be [1,2]
,so I change my code,:
def subb(a,b):
for i in b:
if i in a:
a.remove(i)
return a
Now I want a Pythonic way to replace this function with a simple expression so that I can use the result in function easily.Is it possible?
Thanks.