Cant understand the error? please anyone explain it


#1

def censor(text,word):
    l=len(word)
    wl=[]
    wl=text.split()
    text1=""
    s=" "
    for i in wl:
        if (i==word):
            text1+="*" * l
        else:
            text1+=i
        text1+=" "
    p=len(text1)
    text1[p]=""
    return text1

#2

strings are immutable, so you can't do this:

text1[p]=""

if you want to get rid of the last character, use string slicing


#3

thank you sir. I got it


#4

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