Remove_duplicates


#1

I keep getting this error message: File “python”, line 5
new.append(item)
^
IndentationError: unindent does not match any outer indentation level

I can’t figure out where my indentation is incorrect. Any ideas? My code is below.

def remove_duplicates(sequence):
  new = []
  for item in sequence:
	  if item not in new:
    	new.append(item)
  return new

#2

Read the error and study your code. The error on the console pinpoints to the problem. :slight_smile:


#3

Thanks for responding. I have studied it. BTW, the error on the real console points to the end of the line, not the beginning. So, it points to the last parenthesis. Could you be more specific as to what the indentation error is?


#4

On the console, this is what it says:

IndentationError: unindent does not match any outer indentation level

That means… this part of your code:

doesn’t match any of the indentation levels in your code. I think the arrow (^) points which direction to indent it.
Studying error codes help you be able to find problems in your code.


#7

I know this course is about practice so solutions above are great. But if you want to learn shorter ways and new ways to do stuff (usually you want the shortest way to do something :stuck_out_tongue: ) … :

def remove_duplicates(mix):
----return list(set(mix))

So “set” is a data type that does not allow duplicates so it removes all but one. Then we change it back to list just so it is in wanted format.


#8

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