I am trying to find all the elements that are in list A and not in list B.
I thought something like newList = list(set(a) & !set(b)) or newList = list(set(a) & (not set(b))) would work, but it’s not.
If there a better way to achieve what I’m trying to do other than this?
newList = []
for item in a:
if item not in b:
newList.append(item)
Also important, it needs to be done in Python 2.6
You’re looking for the set difference:
Alternatively, use the minus operator: