# Remove_duplicates

#1

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!

I expect the function to print the singles list and not just modify the input. When I couldn't figure out why I wasnt getting the right answer I tested it using my own list as you can see below and it print a list of [4,5]

``````def remove_duplicates(integers):
singles = []
duplicates = []
new = integers
new.sort()
singles.append(new[len(new) - 1])
for i in range(0, len(new) - 1):
if new[i] == new[i + 1]:
duplicates.append(new[i])
else:
singles.append(new[i])
return singles

lists = [4,5,5,4]

print remove_duplicates(lists)``````

#2

This exercise comes with a gotcha... The order must not change, which means no sorting. Give this some thought, and ping us what you come up with if you still need help. I don't want to say much more than that, just now.

#3

Alright, I appreciate the help. I will keep working at it with that in mind. However instruction number 2 in the directions says "The order in which you present your output does not matter. So returning [1,2,3] is the same as returning [3,1,2]." So I don't think the gotcha was very clear.

#4

I could be thinking of another exercise, altogether. It happens. If there is no error message about being out of order, then I've spoken out of place. I can still see ways your code could be reduced and simplified so leave you with that challenge. Still here if help is needed.

#5

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