10/15 censor: how to replace text

def censor(sentance,word):
  for x in sentance:
    if x == word:
      sentance = sentance.replace(word, "*"*len(word))
  return sentance


i would recommend to build your own algorithm, built-in function like .replace() allow for a single line solution


how about this one
’def censor(sentance,word):
for x in sentance:
if x == word:
" ".join(sentance)
return sentance


x contains read-only values from the list, so that won’t work

and you don’t do anything with the result of the split() action


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