Python3 使用 functools.lru_cache 将列表传递给函数
- 论坛
- Python3 使用 functools.lru_cache 将列表传递给函数
14 浏览
Python3 使用 functools.lru_cache 将列表传递给函数
我想要缓存一个接受列表作为参数的函数,但是当我尝试使用functools.lru_cache
装饰器来实现时,出现了TypeError: unhashable type: 'list'
错误。
import functools @functools.lru_cache() def example_func(lst): return sum(lst) + max(lst) + min(lst) print(example_func([1, 2]))