In the tutorial Mosh loops over a list of numbers and copies the uniques into a new variable. I wrote a different solution to get rid of the duplicates in the list itself, but I don’t understand why it doesn’t work. Can someone tell me why some duplicates are getting removed, but others won’t? I wrote this:
numbers = [2, 2, 4, 1, 3, 4, 2, 6, 1, 1, 1, 1]
for number in numbers:
- if numbers.count(number) > 1:*
-
numbers.remove(number)*
print(numbers)
the output that I’m getting is:
[3, 4, 2, 6, 1, 1, 1]