Remove Duplicates


My code works just fine and I get the correct output but the code academy part gives me the error "Oops, try again. Your remove_duplicates modifies the list that was passed to it. [4, 5, 5, 4] was modified to [4, 4, 5, 5]. Perhaps you should make a copy first!" even though when I print the result of the my function it gives me [4,5]

I realize my code isn't the most streamlined, but it does work so I am frustrated that code academy feels otherwise.

def remove_duplicates(nums):
    for num in nums:
        if num == nums[x-1]:
           if num not in singles:
        elif num != nums[i]:
            if num not in singles:
    print singles 
    return singles


This seems like a reasonable step, except the SCT is expecting the order to be preserved.

That is the only if statement needed.

Neither variable is needed.


If it is expecting the order to be preserved, then why is this in the
instructions: The order in which you present your output does not matter.
So returning [1,2,3] is the same as returning [3,1,2]?


Never saw that before. When no link is provided to the lesson it is a real pain to track down the exact lesson. That leaves us guessing. A while back there was a member whose return value was not what was expected and changing the order seems to have fixed that. Unless it was something entirely different.

Anyway, if you want help with an exercise, please post a link.


Never mind, I was taking the longest possible way around the barn lol


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