Censor


#1

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


It gives this error : try again. Your function fails on censor("hey hey hey","hey"). It returns "[' *** ', ' *** ', ' *** ']" when it should return "*** *** ***".

How do i make it a string instead of a list ?


def censor(text,word):
    star = "*" * len(word)
    broken = text.split()
    tmp = []
    for i in broken:
        if i == word:
            tmp.append(star)
        else:
            tmp.append(i)
    " ".join(tmp)
    return tmp


#2

you should return " ".join(tmp) not the list because you didn't modify your list (tmp)

def censor(text,word):
    star = "*" * len(word)
    broken = text.split()
    tmp = []
    for i in broken:
        if i == word:
            tmp.append(star)
        else:
            tmp.append(i)
    
    return " ".join(tmp)

#3

Thanks Mate, I was returning the list actually.