I understand why modifying the iterable produces wonky results b/c of index shifts but not quite sure why this is wrong.
def checkio(data):
dat1=data
for i in dat1:
if dat1.count(i) <2:
data.remove(i)
return data
when using data=[1,2,3,4,5] the above code still produces [2,4] the same weird errors of index even though "data" is being modified and dat1 is iterated. This below code however does work. When setting a new variable it's acting like its not creating one but only referencing the old one? Is this whats happening? Can someone explain what is wrong with the top code?
def checkio(data):
fuck1=[i for i in data]
for i in fuck1:
if fuck1.count(i) <2:
data.remove(i)
return data
Created at: 2017/03/12 17:06; Updated at: 2017/03/12 18:14