I'm trying to get the number of low-level words (swear words) back in a text, using as base a different .txt file containing the words (profanity). The code I made only returns 1 (one) occurrence, and there are 3 (three). What could I do to improve?
def read_file():
with open(r'C:\movie_quotes.txt') as file: # Abertura do arquivo a ser analisado.
contents = file.read()
print(contents)
file.close()
check_file(contents)
def check_file(text_check):
bad_words = open(r'C:\palavroes_bloqueio.txt') # Palavras a serem procuradas.
contents = list(bad_words)
# print(contents)
for name in contents:
if name in text_check:
print('Bad words found.')
print(text_check.count(name))
bad_words.close()
read_file()