I want to track badwords like english badwords
and i don’t want to use:
if intext.find('badword') != -1:
print("That's a badword")
because it is lengthy and i also don’t want to include
the badword in the code directly
what i tried
#stored the badwords in a variable in a list
a = ['badword1','badword2']
b = input("Enter word")
if b.find(a) != -1:
print("Bad word")
But that doesn’t work! Can anyone help?
Thanx in advance
Advertisement
Answer
Yeah there’s a way to do it.
Code:
import re
import base64 as b64
def base64(m,st):
if int(m) == 0:
st = st.encode('ascii')
st = b64.b64encode(st)
st = st.decode('ascii')
return st
elif int(m) == 1:
st = st.encode('ascii')
st = b64.b64decode(st)
st = st.decode('ascii')
return st
else:
return -1
#PUTTING BADWORDS
BADWORDS = re.compile(base64(1,"d3RmfGZ1Y2t8YXNzaG9sZXxma3xmY2t8ZnVrfGZ1Y3x3dGZrfHh4eHxzZXh5fGFzc3xzaGl0fHNleHxzc3h8c3h8c3hlfGZraW5nfGZrbmd8c3h5fHN4dXxzeGU="))
a = input("enter a word: ")
bad = BADWORDS.search(a)
if str(type(bad)) == "<class 'NoneType'>":
print("The word you typed is: " + a)
else:
print("That's a badword")