feat: Initial commit
This commit is contained in:
27
Laboratorio11/censore.py
Normal file
27
Laboratorio11/censore.py
Normal file
@@ -0,0 +1,27 @@
|
||||
def readBadWords(filename: str):
|
||||
fio = open(filename, "r")
|
||||
bad_words = set()
|
||||
|
||||
for line in fio:
|
||||
bad_words.add(line.strip())
|
||||
|
||||
fio.close()
|
||||
return bad_words
|
||||
|
||||
|
||||
def main():
|
||||
bad_words = readBadWords("bad_words.txt")
|
||||
|
||||
fio = open("input.txt", "r")
|
||||
fout = open("output.txt", "w")
|
||||
|
||||
for line in fio:
|
||||
for wrd in bad_words:
|
||||
line = line.replace(wrd, "*"*len(wrd))
|
||||
|
||||
fout.write(line)
|
||||
|
||||
fio.close()
|
||||
fout.close()
|
||||
|
||||
main()
|
||||
Reference in New Issue
Block a user