Censor


#1



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


Error says : "Oops, try again. Your code looks a bit off--it threw a "string index out of range" error. Check the Hint if you need help!"


def censor(text, word):
    string = []
    result = ''
    i = 0
    text = text.split()
    for p in text:
        if p == word:
            word = '*' * len(word)
            string.append(word)
            result += result[i]
            i += 1
        text = " ".join(string)
    return result
    
    print result


#2

why do you use result? i don't understand. You can perfectly use .join() at end, to join the list into a string

the problem is here:

result += result[i]

result is an empty string, trying to access index will throw an error, i think you attempted to access the list, but mixed it up


#3

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