This is the code that I’ve written for the exercise:
def remove_duplicates(x): current_check = 0 new_list = x new_list.sort() for i in new_list: counter = 0 current_check = i for x in new_list: if counter == 1 and x == current_check: print (True) new_list.remove(x) elif current_check == x: counter += 1 return new_list
There are no syntax error in this code, whats more the code does work, but with only a slight exception. Here is what codecademy returned to me when I executed the code:
It returned the correct list, and I did make a copy of the list, as done in line 3. So I should’ve been able to pass
After further testing, I noticed that the code works but only for list that does not contain purely duplicates. For example if I were to give this argument:
It returns [2,2] when it should’ve returned “” - I’ve tested this on python3, not sure if it makes much difference on python2 though. This is the only exception I’ve found, it doesn’t matter the quantity of the number of arguments or what number is being inputted - as long as it’s purely duplicates, it returns a list of 2 numbers of that same input instead of 1, just as I’ve shown.
I’m not sure if this is a bug in codecademy, or if it was programmed to expect the word “append” (like all the other codes I’ve seen) in the code in order for the code to work, but this certainly is unnatural.
If anyone is willing to spend some time exploring this problem, this would really be helpful - thanks!