|
|
@ -22,3 +22,14 @@ def calculate_word_frequency(file_path):
|
|
|
|
top_10_words = calculate_word_frequency(testfilepath)
|
|
|
|
top_10_words = calculate_word_frequency(testfilepath)
|
|
|
|
for word, freq in top_10_words:
|
|
|
|
for word, freq in top_10_words:
|
|
|
|
print(f"{word}: {freq}")
|
|
|
|
print(f"{word}: {freq}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
'''
|
|
|
|
|
|
|
|
python 提供了一种缓存调用函数的机制
|
|
|
|
|
|
|
|
import functools
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 使用 functools.lru_cache 缓存结果
|
|
|
|
|
|
|
|
@functools.lru_cache(maxsize=None)
|
|
|
|
|
|
|
|
def calculate_word_frequency(file_path):
|
|
|
|
|
|
|
|
...
|
|
|
|
|
|
|
|
retrun result
|
|
|
|
|
|
|
|
'''
|