Skip to content

Commit 794e5a6

Browse files
Merge pull request #1407 from python-pitfalls/master
removed a pitfall where the code was using a default mutable argument
2 parents a442805 + 5697073 commit 794e5a6

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

tf_idf_generator.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def paint(str, color='r'):
6969
TAG = paint('TF-IDF-GENE/', 'b')
7070

7171

72-
def find_tf_idf(file_names=['./../test/testdata'], prev_file_path=None, dump_path=None):
72+
def find_tf_idf(file_names=None, prev_file_path=None, dump_path=None):
7373
'''Function to create a TF-IDF list of dictionaries for a corpus of docs.
7474
If you opt for dumping the data, you can provide a file_path with .tfidfpkl extension(standard made for better understanding)
7575
and also re-generate a new tfidf list which overrides over an old one by mentioning its path.
@@ -85,6 +85,8 @@ def find_tf_idf(file_names=['./../test/testdata'], prev_file_path=None, dump_pat
8585
idf : a dict of unique words in corpus,with their document frequency as values.
8686
tf_idf : the generated tf-idf list of dictionaries for mentioned docs.
8787
'''
88+
if file_names is None:
89+
file_names = ['./../test/testdata']
8890
tf_idf = [] # will hold a dict of word_count for every doc(line in a doc in this case)
8991
idf = {}
9092

0 commit comments

Comments
 (0)