Return to Snippet

Revision: 69053
at April 11, 2015 09:17 by arielinfante


Initial Code
bad_list = ["suck", "bad", "horrible", "crap"]
sentence = "This bad could really suck as a horrible horrible. sentence"
 
def censor(sentence, bad_list):
    list_sentence = sentence.split(" ")
    symbols = "!@#$%^&*()_+{}|:<>?,./;'[]\=-\""
 
    replaced_sentence = []
 
    no_sym = ""
 
    for word in list_sentence:
        checked = 0
        for bad_word in bad_list:
            replaced_word = ""
            one_time = True
        
            if word == bad_word:
                replaced_word = "*" * len(word)
                checked += 1
                break
            else:
                if checked < 1:
                    replaced_word = word
 
        replaced_sentence.append(replaced_word)
 
    replaced_sentence = " ".join(replaced_sentence)
 
    return replaced_sentence
 
print censor(sentence, bad_list)

Initial URL


Initial Description
A simple Python censor script that takes 2 arguments. One is for the text you want to censor and the other is the list of words that should not be viewed.

Initial Title
Python Censorship

Initial Tags
python

Initial Language
Python