Possible duplicate:Python List Subtraction Operation
I want to remove common items between two lists. I mean something like this
a=[1,2,3,4,5,6,7,8] b=[2,4,1] # I want the result to be like res=[3,5,6,7,8]
Is there any simple pythonic way to do this?
use sets:
res = list(set(a)^set(b))
The set has methods: http://docs.python.org/3/library/stdtypes.html#set
print (set (a) .difference (b))