-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcensor.py
44 lines (32 loc) · 797 Bytes
/
censor.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
from cs50 import get_string
from sys import argv
words = set()
def main():
if len(argv) != 2:
print("Usage: python censor.py dictionary")
exit(1)
load(argv[1])
input = get_string("What messasge would you like to censor? ")
tokens = input.split()
limit = 0
for i in tokens:
if check(i):
for j in i:
print("*", end="")
else:
print(i, end="")
limit = limit + 1
if limit != len(tokens):
print(" ", end="")
print("\n")
return True
def load(banned):
file = open(banned, "r")
for line in file:
words.add(line.rstrip("\n"))
file.close()
return True
def check(word):
return word.lower() in words
if __name__ == "__main__":
main()