Code works in Python2 and Python3 but throws and error in Code Academy?


#1

def remove_duplicates(dups):
    nodups = []
    end = len(dups)-1
    sortdups = list(dups)
    sortdups.sort()
    for i in range(0,end):
        if sortdups[i] != sortdups[i+1]:
              nodups.append(sortdups[i])
    nodups.append(sortdups[i+1])            
    return nodups

#2

the editor is not recognizing spaces, must be a hidden character issue, I will re-type the program.


#3

Is there a reason this line repeats?


#4

Sorry for any confusion, the editor dropped all of my indents.
The statement just before the return insures that the last data item is included on the output.


#5

Are you getting the correct output, or not? If not, then there is your culprit.


#6

The error message in question seems like relevant information, don't you think?

I'm guessing that it's telling you what failed and what the input was.
I'm also guessing that you didn't try the failing input when you ran the code yourself.

So your own testing doesn't cover the case that codecademy finds a problem with.
If you run no tests at all, if you don't run your code at all, then that will also have the outcome that there is no error.


#7

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