It returns "*** *** *** " when it should return "*** *** ***". Error


#1



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


I guess I'm not doing it the way it wants me to because I get this error "Oops, try again. Your function fails on censor("hey hey hey","hey"). It returns "*** *** *** " when it should return "*** *** ***".


From what I can see, the two texts in the error report are exactly the same


def censor(text, word):
    count = len(word)
    t = text.split()
    y = ''
    for char in t:
        if char == word:
            y += '*' * count + ' '
        else:
            y += char
    return y


#2

no, they are not. lets replaces the spaces with underscores, your code:

***_***_***_

desired output:

***_***_***

you have a space too much at the end, you could slice it off? [:-1] is what you need for the slice, and slicing shouldn't be new at this point in the course, right?


#3

Thanks, mate! Im sure I have learned slicing before but I just started again from a very long absence.

The new code if someone is interested, I added another space after uncensored characters aswell


#4

Thanks man, i really learnt and solved my problem from this


#5