Censor bad words in Python using better-profanity
Last Updated :
24 Jan, 2021
In this article, we will learn how to Censor bad words using Python. For this, we are using the better_profanity module from python.
Installation
pip install better_profanity
For censoring bad words, we are using profanity.censor() method from better_profanity. So, we discuss first its syntax and arguments.
Syntax: profanity.censor(text, censor_char=’*’)
Parameters:
text : text to be censor
censor_char : ‘*’ by default, character to censor bad words
Return value: censored text
Approach:
- Import package (profanity)
- Declare or input the text to be censored.
- Use profanity.censor() method and get the censored text.
- Print censored text.
Example 1:
Python3
from better_profanity import profanity
text = "What the shit are you doing?"
censored = profanity.censor(text)
print (censored)
|
Output:
What the **** are you doing?
Example 2:
Python3
from better_profanity import profanity
text = "What the shit are you doing?"
censored = profanity.censor(text, '$' )
print (censored)
|
Output:
What the $$$$ are you doing?
Share your thoughts in the comments
Please Login to comment...