10/15 censor: how to replace text


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

#2

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


#3

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


#4

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


#5

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