Reputation: 180401
I have the following code:
class Memoize:
def __init__(self, f):
self.f = f
self.memo = {}
def __call__(self, *args):
if not args in self.memo:
self.memo[args] = self.f(*args)
return self.memo[args]
@Memoize
def fib(n):
if n < 2:
return n
else:
return fib(n-1) + fib(n-2)
I am trying to improve my basic programming skills, I have the following problem that I cannot figure out how to do, I want to be able to put all the values of fib(n-1) + fib(n-2) in a list so I can filter the list of values based on other criteria. What is the best way to achieve this? Thanks
Upvotes: 0
Views: 106
Reputation: 3908
How about just a simple list comprehension?
fiblist = [fib(n) for n in xrange(1,n+1)]
Upvotes: 3