Remove_duplicates


#1

<PLEASE USE THE FOLLOWING TEMPLATE TO HELP YOU CREATE A GREAT POST!>

<Below this line, add a link to the EXACT exercise that you are stuck at.>

<In what way does your code behave incorrectly? Include ALL error messages.>
Error Message: remove_duplicates([4, 5, 5, 4]) returned [4] instead of [4, 5]

<What do you expect to happen instead?>
append the way it should and print it out so I can see that it ran correctly

```python

def remove_duplicates(num):
inlist = num[:] #tried this with and without the [:]
outlist = [] #does this need a space or something?
for i in inlist: #this should be fine
if i not in outlist: #so should this
outlist.append(i) #not appending according to error message
print outlist #nothing prints no matter what is entered here
return outlist

<do not remove the three backticks above>

#2

return outlist

return terminates a function.whenever a return statement is reached it ends the function at that moment. so the return statement should not be inside for loop .if it is in the for loop then it ends the function at its first iteration so make sure the return statement is outside of for loop.


#3

Fabulous. Thank you. Still won’t print anything though (even if I move the print outside the loop). Is there a list of ‘print rules’ somewhere?

Auto-indent like in Matlab would be a nice addition to Python.


#4

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