I want to track badwords like english badwords
and i don’t want to use:
JavaScript
x
3
1
if intext.find('badword') != -1:
2
print("That's a badword")
3
because it is lengthy and i also don’t want to include
the badword in the code directly
what i tried
JavaScript
1
6
1
#stored the badwords in a variable in a list
2
a = ['badword1','badword2']
3
b = input("Enter word")
4
if b.find(a) != -1:
5
print("Bad word")
6
But that doesn’t work! Can anyone help?
Thanx in advance
Advertisement
Answer
Yeah there’s a way to do it.
Code:
JavaScript
1
28
28
1
import re
2
import base64 as b64
3
4
def base64(m,st):
5
if int(m) == 0:
6
st = st.encode('ascii')
7
st = b64.b64encode(st)
8
st = st.decode('ascii')
9
return st
10
elif int(m) == 1:
11
st = st.encode('ascii')
12
st = b64.b64decode(st)
13
st = st.decode('ascii')
14
return st
15
else:
16
return -1
17
18
#PUTTING BADWORDS
19
BADWORDS = re.compile(base64(1,"d3RmfGZ1Y2t8YXNzaG9sZXxma3xmY2t8ZnVrfGZ1Y3x3dGZrfHh4eHxzZXh5fGFzc3xzaGl0fHNleHxzc3h8c3h8c3hlfGZraW5nfGZrbmd8c3h5fHN4dXxzeGU="))
20
21
a = input("enter a word: ")
22
23
bad = BADWORDS.search(a)
24
if str(type(bad)) == "<class 'NoneType'>":
25
print("The word you typed is: " + a)
26
else:
27
print("That's a badword")
28