Jun-09-2020, 02:11 PM
This code removes the duplicates in two lists. But when I run it, one of the duplicates is not removed. It beats me. Can someone explain to me why.
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)It prints: [2,3,4] but item 2 is still a duplicate. Have run it several times and baffled.