From be3c7436b28f162e6cb7e74101fb09bcd0cb4222 Mon Sep 17 00:00:00 2001 From: jack <512546046@qq.com> Date: Wed, 13 Dec 2017 17:30:45 +0800 Subject: [PATCH] Update fibo_speed.rst def fib_cached(n, cache={}): if n < 2: return n try: val = cache[n] except KeyError: val = fib(n-2) + fib(n-1) cache[n] = val return val Maybe there is a typo error in function body : val = fib(n-2) + fib(n-1) should be like this: val = fib_cached(n-2,cache) + fib_cached(n-1,cache) --- doc/source/fibo_speed.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/fibo_speed.rst b/doc/source/fibo_speed.rst index b16205b..3976c06 100644 --- a/doc/source/fibo_speed.rst +++ b/doc/source/fibo_speed.rst @@ -189,7 +189,7 @@ So far we have looked at pushing code into Cython/C to get a performance gain ho try: val = cache[n] except KeyError: - val = fib(n-2) + fib(n-1) + val = fib_cached(n-2,cache) + fib_cached(n-1,cache) cache[n] = val return val