3 ms·
The Python version is also goofy since it doesn't support keyword arguments for the wrapped function: def memoize(func): cache = {} def wrapper(
by bpeebles 5y ago
The Python version is also goofy since it doesn't support keyword arguments for the wrapped function:
def memoize(func):
cache = {}
def wrapper(*args):
if args in cache:
return cache[args]
else:
cache[args] = func(*args)
return cache[args]
return wrapper
and why wouldn't you just use
# or @functoolscache (3.9+).
@functools.lru_cache(maxsize=None)
def f(*args, **kwargs):
pass