Not seeing your question? It may still have been asked before – try () in the top-right of this page. Still can’t find it? Ask it below by hitting the reply button below this post ().
Other FAQs
The following are links to additional questions that our community has asked about this exercise:
def censor(text, word):
words = text.split()
result = ''
stars = '*' * len(word)
count = 0
for i in words:
if i == word:
words[count] = stars
count += 1
I just so confused with this part of codes
count = 0
for i in words:
if i == word:
words[count] = stars
count += 1
result =' '.join(words)
The bit of code I wrote passed the test but I don’t think it’s the correct way to do it given what I saw mentioned about the list not being updated if only a replacement is used.
Would someone be able to tell me if there’s anything inherently wrong with this:
def censor(text,word):
if word in text:
text = text.replace(word,"*"*len(word))
return text
that you could argue about, i think the correct output should be:
this hack ** a wack hack
vs:
th** hack ** a wack hack
what your code gives.
but there are no clear specification in this regard. But if it was for censoring like on this forum, hello would be censored to ■■■■ o, not really nice.