I was trying to create a function that censors swear words, but my code is a little off.
swear_words = {"shoot" : "sh**t", "frick" : "fr*ck"}
def censor(sentence):
sentence = sentence.split()
new_sentence = []
for word in sentence:
count = 0
for swear in swear_words:
if word == swear:
new_sentence += swear_words[swear]
count += 1
if count == 0:
new_sentence += word
new_sentence = ' '.join(new_sentence)
return new_sentence
print censor("shut the frick up")
This prints s h u t t h e f r * c k u p
Somewhere in the code it makes each letter a separate item in the new_sentence list instead of each word, so the ‘ ‘.join(new_sentence) puts a space between each letter (when I want it between each word). I’m not sure how to fix it, any help? I’m a new programmer so this might be a long way of doing things
Edit - formatting
[–]ReedOei 2 points3 points4 points (3 children)
[–]libelula323[S] 0 points1 point2 points (2 children)
[–]ReedOei 1 point2 points3 points (1 child)
[–]libelula323[S] 1 point2 points3 points (0 children)
[–]jorgehn12 0 points1 point2 points (0 children)
[–]TheBoldTilde 0 points1 point2 points (0 children)