Censor


#1

Hi!

My code is returning "['', '', '', '', '', '', '', '', '*']" instead of "*** *** ***". Nor really shure why. Please help!

Thanks!

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

#2

return new_text
    ' '.join(new_text)
    
    return new_text

You returned new_text before you could join() it. :slight_smile:


#3

I changed that but it still return the same result :disappointed:


#4

Maybe using append() rather than += will work.

Could you post the updated code? :slight_smile:


#5

This will work if we write i in a list.

new_text += [i]

otherwise, it would be,

new_text.append(i)

#6

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