From eed0bd8fc0fc95dc8f46fb725f7a337a0fc384bd Mon Sep 17 00:00:00 2001 From: zj3D Date: Fri, 8 Mar 2024 15:49:51 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BC=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 计算设备/缓存/84.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/计算设备/缓存/84.py b/计算设备/缓存/84.py index 962595c..6cd67ad 100644 --- a/计算设备/缓存/84.py +++ b/计算设备/缓存/84.py @@ -21,4 +21,15 @@ def calculate_word_frequency(file_path): # 测试函数 top_10_words = calculate_word_frequency(testfilepath) for word, freq in top_10_words: - print(f"{word}: {freq}") \ No newline at end of file + print(f"{word}: {freq}") + +''' +python 提供了一种缓存调用函数的机制 +import functools + +# 使用 functools.lru_cache 缓存结果 +@functools.lru_cache(maxsize=None) +def calculate_word_frequency(file_path): + ... + retrun result +''' \ No newline at end of file