10. Censor. Which value takes 'i'?


#1

Hi all! Who can explain: which value takes 'i'??

def censor(text, word):
text = ("this hack is wack hack")
text = text.split(" ")
for i in range(0, len(text)): /// Which value takes 'i' here?
if text[i] == word: /// Which value takes 'i' here?
print word
text[i] = "*" * len(word) /// Which value takes 'i' here?
return " ".join(text)

print censor("text", "hack")


#2

why not simple add a print statement inside the function to see which values i has a different parts of the program? Looking at it, i would say it would take 0 till len of text -1.

you can use this number to access the words in the text variable.

This is dangerous:

text = ("this hack is wack hack")

you already have text as function parameter:

def censor(text, word):

no need to overwrite it, you can pass it as argument when calling the function:

print censor("this is a wack hack", "hack")