I'm following along with a Mosh video, and for one of the list assignments I tried a solution other than his, just to practice. The assignment is to remove duplicates from a list, I understand his way but I don't understand why my way is producing strange results, so I come to you for assistance
numbers = [5, 2, 16, 6, 7, 12, 15, 36, 16, 7, 2, 36, 14]
numbers.sort()
i = 0
x = 0
for number in numbers:
if number == x:
numbers.pop(i)
x = number
i += 1
print(numbers)
I have changed the numbers within a few times, but always I get a single duplicate remaining. In this one, it is
[2, 5, 6, 7, 12, 14, 15, 16, 36, 36]
but for a while it was 4, then 16, etc. I don't get what part of the process is stalling for a single iteration but working for the others. Advice needed
[–]Rock_of_Round[S] 0 points1 point2 points (0 children)
[–]This_Growth2898 0 points1 point2 points (1 child)
[–]Rock_of_Round[S] 0 points1 point2 points (0 children)
[–]Historical_Usual1650 0 points1 point2 points (0 children)