I have a list (ex: [1, 2, 2, 3, 4, 3]
) and I need to only keep the first occurrence of any of the elements in the list (ex: the list should become [1, 2 ,3, 4]
). I know that I could do something like this:
badList = [1, 2, 2, 3, 4, 3]
goodList = []
for element in badList:
if element in goodList:
continue
goodList.append(element)
print (goodList)
However, this is a very messy solution, and I am hoping there is a more elegant way.