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)
            result += result[i]
            i += 1
        text = " ".join(string)
    return result
    print result


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


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