Code not working


#1

def remove_duplicates(numbers):
for i in range(len(numbers)):
key=numbers[i]
for k in range(i+1,len(numbers)):
if (numbers[k]==key):
numbers.pop(numbers[k])
print numbers

remove_duplicates([1,2,2,1])


#2

pop/remove/del is a bad idea to solve this problem because of index shift

I recommend adding the numbers to a new list, you could use something like: if .. not in .., which allows you to check if a number is already in the list


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.