Is there a decorator to simply cache function return values?

Consider the following: @property def name(self): if not hasattr(self, ‘_name’): # expensive calculation self._name = 1 + 1 return self._name I’m new, but I think the caching could be factored out into a decorator. Only I didn’t find one like it 😉 PS the real calculation doesn’t depend on mutable values 19 Answers 19

What is the difference between bottom-up and top-down?

The bottom-up approach (to dynamic programming) consists in first looking at the “smaller” subproblems, and then solve the larger subproblems using the solution to the smaller problems. The top-down consists in solving the problem in a “natural manner” and check if you have calculated the solution to the subproblem before. I’m a little confused. What … Read more