10. censor



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(" ")
    for x in text:
        if x==word:
            txt+=(" ")
            txt+=(" ")    
    return txt


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


I solved the extra space problem with:

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


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