Oops, try again. Your function fails on censor("hey hey hey","hey"). It returns "***" when it should return "*** *** ***"


#1



https://www.codecademy.com/courses/python-intermediate-en-rCQKw/1/4?curriculum_id=4f89dab3d788890003000096#


Oops, try again. Your function fails on censor("hey hey hey","hey"). It returns "" when it should return " *** ***".

Could anyone explain it to me,what's wrong with my code. Why it fails in the given example?


def censor(text,word):
    list_of_words=word.split()
    for index in range(len(list_of_words)):
        if word==list_of_words[index]:
            list_of_words[index]="*"*len(word)      
    return " ".join(list_of_words)


#2

this line:

list_of_words=word.split()

can you tell me what string you split into a list?


#3

It's quite obvious I'm splitting string variable word into my list list_of_words


#4

does it make sense to split word? What does word contain?

My question was intended to make you think about what you split and why


#5

I should have splitted text and not word. It was only a question of me confusing these two variables and not a question of me not understanding what the function censor should look like.


#6

Yes, that was all. But small mistakes can be difficult to find.


#7

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