Censor


#1



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

My code error does not make sense this is what it says:
Oops, try again. Your function fails on censor("Yo go fro yo go","go"). It returns "Yo ** fro yo **" when it should return "Yo ** fro yo **".

I do not understand the error message

def censor(text, word):
    split_text = text.split()
    new_text = []
    for x in split_text:
        if x == word:
            new_text.append(len(x)*"*")
        else:
            new_text.append(x + " ")
    return " ".join(new_text)


Thank you in advance


#2

The error message makes both look the same, but the truth is they are not. HTML cannot render two %20 characters in a row. However, your elements are being stored with an extra space that once joined have two space separations at given intervals; to wit:

That means your returned strings don't match the expectation, even though it is not possible to render a correct error message (in this regard).


#3

Thank you so much i have fixed it and now it works


#4

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