You shouldn't alter a list while iterating over it, it loses track of the position, make a copy of the list to iterate and alter the original.
def removeDups(L1, L2): """Assumes that L1 and L2 are lists. Removes any element from L1 that also occurs in L2""" for e in L1[:]: if e in L2: L1.remove(e) L1 = [1, 2, 3, 4, 6] L2 = [1, 2, 5, 6] removeDups(L1, L2) print('L1 =', L1)
Output:L1 = [3, 4]