10/15 Unorthodox decision. Sort of


Well, it seems I googled some stuff I probably shouldn't have yet :smile:
And I guess I'm not the first one who comes up with the following solution, but anyways.

Here it is:

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

Soooo...my question is: what is the proper decision to this exercise? What's the point of generating a list?

(Also, maybe this will help someone who's stuck...)


I don't know how the python built-in replace method is implemented(maybe they use lists) but what if you could not use the built in replace method then how would you implement the sensor method? Try to implement it without the replace method



Well, you should probably google strings for python. After you do such you will notcie that in Python strings are immutable.

Being such, you have to use some kind of container to change them into something else. Even string methods hold onto the data while it is being transformed.

Also, the "proper" choice for any programming is what works and nothing else. As you become more and more familiar with the syntax of a language you will decide that different things are proper.

Just remember to keep an open-mind and you will always improve what you are doing!

Also you only need to do as follows for the replace code,

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