10.censor


#1

def censor(text, word):
l=[]
st=""
mone=0

for a in text:
    mone+=1
    if a!=" ":
        st+=a
        if mone==len(text):
            l.append(st)
    else:
        l.append(st)
        st=""

for b in l:
    if b==word:
        b="*"*len(b)

ntext=""

for c in l:
    ntext+= c+" "

return ntext[0:len(ntext)-1]

I looked at the hint and saw that there's an easier way but I still don't undertsand why my code doesn't work, can someone please explain to me?
it returns ntext as hey hey hey which is like the original but it's as if it skips the part where i say to change the word to to the asterisks..


#3

ok so i solved it by replacing the part with the *** with this:
for w in range(len(l)):
if l[w-1]==word:
l[w-1]=""len(l[w-1])

not entirely sure why the first one didn't work but i tried a different approach anyway. I'd still like an answer though:)