So I have a list:
s = ['cat','dog','cat','mouse','dog']
And I want to be able to iterate through the list and remove the duplicates, WITHOUT using the set() function! So for example it should remove 'cat' and position s[2] BUT keep 'cat' at position s[0]. It then needs to do the same thing for 'dog', ie. keep 'dog' at position s[1] but remove 'dog' from position s[4].
So the output is then:
s = ['cat','dog','mouse']
I have tried to use i and j as index positions in the list, and check whether the element at position i is equal to the element at position j. If so, it will remove it and increment the value of j by 1, if not then it will leave it and just increment the value of j. After the whole list has been iterated through, it will increment the value of i and then check the whole list again, for the new element. Below:
i = 0
j = 1
for a in range(len(s)):
for b in range(len(s)):
if s[i] == s[j]:
s.remove(s[j])
j = j + 1
else:
j = j + 1
i = i + 1
What am I doing wrong here?