Censor 10/15: Indentation Error


#1

I keep getting an indentation error and I have no idea what keeps causing it. Sometimes I delete spaces, tab the exact same way, and it gives an indentation error for the for loop. My code is below. Thanks.

def censor(text, word):
	new_list = text.split()
	for i in new_list:
    if i == word:
      position = new_list.index(i) 
      del(new_list[position])
      new_list.insert(position, ['*']*len(i))
      
  newer_list = " ".join(new_list)    
  return newer_list 

#2

For some reason the code above shows that my if statement isn’t indented within the for loop but that’s not how I copied and pasted it. Hope this updated one helps.

def censor(text, word):
	new_list = text.split()
	for i in new_list:
    if i == word:
      position = new_list.index(i) 
      del(new_list[position])
      new_list.insert(position, ['*']*len(i))
      
  newer_list = " ".join(new_list)    
  return newer_list

#3

It’s still pasting weird but it looks right in codeacademy but I get the error “File “python”, line 4
if i == word:
^
IndentationError: unindent does not match any outer indentation level”


#4

What you have there may look right on the screen in the editor but pasted in here it reveals the TABs and the SPACEs. Change all your indentation to spaces so there in not a mix.


#5

Thanks, that did the trick.


#6

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