Small troubles


So, in “censor,” the tip is to use string.split() and " ".join(list) , however, not only do I not remember how these work, but I can’t seem to find them when I go through the previous lessons, so, if you can inform me which lessons they are discussed in, that would be greatly appreciated.

Also, because I’m pretty stubborn, I tried to code it without those functions, but it seems to have some problems.

def censor(text,word):
  for char in text:
    if z>0:
    elif char==word[0]:
      if text[b:b+a]==word:
This text will be hidden

       # result+=char
  return result

Nevermind the problems, I found out what was wrong. I really stupidly took the index of the character in the word, instead of in the phrase, and since almost all the phrase just so happened to start with the word to be censored, it always gave a positive. I still haven’t found the lesson where they discuss those functions, however, so that would still be appreciated.


python also has documentation? A simple google search on python split and python join gives plenty of examples and explanations, without those function the solution becomes a lot more complicated.

it can be a fun challenge to attempt it without those function. There are no comments in your code, how do you detect the different words in text?


Yeah, I thought about just googling it, but… I thought that maybe there would also be an answer the problems in the code without the functions.
If you managed to see my comment before I just edited it saying that I fixed it, I explained that I had it look for the first character in the word to be censored, then took a slice out of the text of the same length as the word, and checked to see if it was the same as the word.
Unless you mean “word” as like, things seperated by spaces. In which case, I didn’t. ("they", "hey") would get censored to t***.


That depends on the purpose, but i would say they should be uncensored.

you could loop over text, and look for spaces (" "), this way you can create a list of the different words in the text string. This is also how split works.

this forum also has a censor function, but pass is allowed while ■■■ is not allowed. And hello is allowed while ■■■■ is not allowed


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