Skip to content

Commit 13846d5

Browse files
authored
Update word_frequency_functions.py
1 parent 4772fd0 commit 13846d5

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

machine_learning/word_frequency_functions.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,14 @@ def document_frequency(term: str, corpus: str) -> int:
7575
the third document in the corpus.")
7676
(1, 3)
7777
"""
78-
corpus_without_punctuation = corpus.translate(
78+
corpus_without_punctuation = corpus.lower().translate(
7979
str.maketrans("", "", string.punctuation)
8080
) # strip all punctuation and replace it with ''
81-
documents = corpus_without_punctuation.split("\n")
82-
lowercase_docs = [document.lower() for document in documents]
81+
docs = corpus_without_punctuation.split("\n")
82+
term = term.lower()
8383
return (
84-
len([doc for doc in lowercase_docs if term.lower() in doc]),
85-
len(documents),
84+
len([doc for doc in docs if term in doc]),
85+
len(docs),
8686
)
8787

8888

0 commit comments

Comments
 (0)