Removing common elements between two lists

advertisements

Possible Duplicate:
Python list subtraction operation

I want to remove the common elements 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))