zj3D 9 months ago
parent 734c33e82f
commit eed0bd8fc0

@ -21,4 +21,15 @@ 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
'''
Loading…
Cancel
Save