Skip to content

Instantly share code, notes, and snippets.

@bekzat-shayakhmet
Forked from wzpan/fibonacci.py
Last active December 19, 2020 11:23
Show Gist options
  • Save bekzat-shayakhmet/fee58658bb7ae2abe1b6a23adf14b58b to your computer and use it in GitHub Desktop.
Save bekzat-shayakhmet/fee58658bb7ae2abe1b6a23adf14b58b to your computer and use it in GitHub Desktop.
Python - Fibonacci Iterator
class Fib:
def __init__(self, max):
self.max = max
def __iter__(self):
self.a = 0
self.b = 1
return self
def __next__(self):
fib = self.a
if fib > self.max:
raise StopIteration
self.a, self.b = self.b, self.a + self.b
return fib
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment