10. Censor


#1



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


Hey, my function returns the text just as he was. I can't figure out where the problem lies.


I thought, that through if word==x: x= ""len(word) the string would be replaced, but somehow it doesn't. I'd be grateful for help!


def censor(text,word):
    text=text.split()
    for x in text:
        if word==x:
            x= "*"*len(word)
    d=" "
    text= d.join(text)
    return text

print censor("fu fu fo", "fo")


#2

here:

for x in text:

using a for loop will give you read only values from the list, any changes made to x won't persist

If you want to do this, use range() in the for loop, this gives you indexes which you can use to manipulate text list


#3

Ok solved the problem, thank you very much!!


#4

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