I'm trying to implement a difference function, which subtracts one list from another and returns the result. Here is what i have so far:
def array_diff(a, b):
for e in b[:]:
for i in a:
a.remove(i)
return a
in1 = [1, 2, 2]
in2 = [1]
print(array_diff(in1, in2))
I have two sample tests that i'd like to run.
Test.assert_equals(array_diff([1,2,2], [1]), [2,2], "a was [1,2,2], b was [1], expected [2,2]")
Test.assert_equals(array_diff([1,2,2], [2]), [1], "a was [1,2,2], b was [2], expected [1]")
How would i be able to remove the same value more than once?