removes the duplicates in a list
numbers = [5, 8, 5, 4, 4, 7, 7, 3, 1, 8]
numbers.sort()
print(numbers)
value = 0
for x in numbers:
if value == x:
numbers.remove(x)
else:
value = x
print(numbers)
it's working for 4 and 7 but not for 5 and 8
output:
[1, 3, 4, 4, 5, 5, 7, 7, 8, 8]
[1, 3, 4, 5, 5, 7, 8, 8]
Note: I haven't seen the solution yet. It will be better if you point out the bug instead of posting the whole code