Censor exercise


#1




When I run it, this error comes up: "Oops, try again. Your code looks a bit off--it threw a "'list' object has no attribute 'join'" error. Check the Hint if you need help!"


Where did I go wrong?


def censor(text, word):
    text = text.split(" ")
    result = []
    for i in text:
        if i == word:
            result += "*" * len(word)
            
    return result.join(" ")


#2

The proper syntax for join is

" ".join(result)

#3

Thanks! I an going to try it!!


#4

Pretty much worked, except for this "Oops, try again. Your function fails on censor("hey hey hey","hey"). It returns "* * * * * * * * *" when it should return "*** *** ***"."


#5

def censor(text, word):
z = len(word)
x = ("*" * z)
return text.replace(word, x)

for me this worked


#6

You can also shorten the code:
def censor(text, word):
return text.replace(word, '*' * len(word))


#7

You dont need to put anything in the () for text.split().


#8

Thanks for the help, I get it now!


#9

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