"Both factorial and fibonacci are examples of tail recursion.
Tail recursion is considered a bad practice in languages like Python, however, since it uses more system resources than the equivalent iterative solution."
Uh no, those implementations were plain recursion. Tailrecursion is basically the same as iteration but Python doesn't optimize tail-calls so the stack will blow anyway. He defines tail-recursion something along the lines as "if the last statement ina function is a recursive call". NO! From wikipedia: "In computer science, tail recursion (or tail-end recursion) is a special case of recursion in which the last operation of the function is a recursive call"
And while the solution he presents in the next chapter: previous = {0: 0, 1: 1} def fibonacci(n): if previous.has_key(n): return previous[n] else: new_value = fibonacci(n-1) + fibonacci(n-2) previous[n] = new_value return new_value
works the simple idiomatic way is simply: def fib(n): a, b = 1, 0 while n: a, b, n = b, a+b, n-1 return b
Sad that most people don't catch that.