Edit: After the person asking the question simply did not know about __hash__ , I provided this information in a comment:
To use sets, do __hash__ . Therefore, if obj1 == obj2 , when obj1.a == obj2.a and ob1.b == obj2.b , __hash__ should be return hash((self.a, self.b)) , and your sets will work as expected.
This solved their problem, and they switched to using sets.
The rest of this answer is now deprecated, but it is still correct (but terribly inefficient), so I will leave it here.
This code does what you want. In the end, newx and newy are nonoverlapping elements of x and y in particular.
x = [1,2,3,4,4,5,6,7,7] y = [3,4,5,6,7,8,9,10] # you can leave out bad and just compare against # x at the end if memory is more important than speed newx, bad, newy = [], [], [] for i in x: if i in y: callsomefunction(i) bad.append(i) else: newx.append(i) for i in y: if i not in bad: newy.append(i) print newx print newy
However, I know, without even seeing your code, that this is the wrong way to do this. You can, of course, do this with kits, but if you do not want this, then it is up to you.