Mini question about Censor


#1

I have written a code and it worked but I didn't use join or split functions I have just used replace and it worked so I want to know if that is fine or not ?Here is the the code.

def censor(text,word):
    length = len(word)
    replace = "*" * length
    text = text.replace(word,replace)
    return(text)

#2

given you are here to learn, using a built in function like .replace() doesn't teach you much, i would recommend you to write your own algorithm.

also, .replace() doesn't always give desired output. for example:

censor("this is a example", "is")

using replace, this will also get censored (th**)

so depending on the purpose of your program, this might not be desired

for example, this forum has a language filter. ■■■■ (first four letters of hello) is being censored but hello isn't.


#3

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