This is my iterator for Fib squence:
class fibo:
def __init__(self, n=0):
self.n = n
self.x1 = 0
self.x2 = 1
def next(self):
if self.n == 0:
raise StopIteration
else:
self.n = self.n -1
tmp = self.x1
self.x1, self.x2 = self.x2, self.x1 + self.x2
return tmp
def __iter__(self):
return self
The result is
>>> [i for i in fibo(15)]
[0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377]
How do I modify the code such that instead of iterating over the first n Fibonacci numbers, successive calls iterate over the next n numbers, e.g., ????
>>> f=fibo(5)
>>> [i for i in f]
[0, 1, 1, 2, 3]
>>> [i for i in f]
[5, 8, 13, 21, 34]
>>> [i for i in f]
[55, 89, 144, 233, 377]
>>> [i for i in f]
[610, 987, 1597, 2584, 4181]