10. censor


#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 "*** *** ***".


so the only problem here is that i have an extra space at the end of the string, how can i remove it?


Replace this line with your code. 
def censor(text, word):
    text=text.split(" ")
    txt=""
    for x in text:
        if x==word:
            txt+=("*"*len(word))
            txt+=(" ")
        else:    
            txt+=(x) 
            txt+=(" ")    
    return txt


#2

oh nevermind i solve it by adding return txt[:(len(txt)-1)] haha but i like to see how u guys fix it


#3

I solved the extra space problem with:

if new_text[len(new_text) - 1] == ' ':
        new_text.pop(len(new_text) - 1)

#4

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