Что меня затруднило, так это то, что я следую " example» на их курсе, и он выдает ошибку в блокноте Jupyter, хотя она точно такая же, как и на их курсе:
Код: Выделить всё
def memoize(func):
'''Store the results of the decorated function for fast look up'''
#Store results in a dict that maps arguments to results
cache = {}
#As usual, create the wrapper to create the newly decorated function
def wrapper(*args, **kwargs):
# If these arguments havent been seen before...
if (args, kwargs) not in cache:
#Call func() and store the result.
cache[(args, kwargs)] =func(*args, **kwargs)
#Now we can look them up quickly
return cache[(args, kwargs)]
return wrapper
Код: Выделить всё
@memoize
def slow_function(a,b):
print('Sleeping...')
time.sleep(5)
return a+b
Заранее спасибо.
Подробнее здесь: https://stackoverflow.com/questions/650 ... sing-cache