0
I’m trying to get as a return the amount of low-level words (bad words) in one text, using as a basis another file . txt containing the words (bad words). 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()
If the word
foo
is a dirty word,foobar
shall be accounted for as an occurrence offoo
?– Woss
No, In case I wanted to pick up the whole word. In case Obar would not enter. Thank you!
– Marcio
But this point addressed by you was great. Because if you happen to have no space between a word and another at any point in the text. would not return. Right?
– Marcio
It’s there! Only I’m using a file . txt with the words I want to search in another file .txt. Thank you!
– Marcio
But it’s exactly the same problem, just read the contents of the file.
– Woss
Right! I’m testing the code and I’ll get back to you soon. Thank you!
– Marcio