Skip to content

Instantly share code, notes, and snippets.

@TheOnlyWayUp
Last active August 2, 2022 12:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TheOnlyWayUp/cf60a2ec96c9db9cb27f0ddb76dd2212 to your computer and use it in GitHub Desktop.
Save TheOnlyWayUp/cf60a2ec96c9db9cb27f0ddb76dd2212 to your computer and use it in GitHub Desktop.
Basic OOP-Based Fibonacci Sequence in Python
class UserList:
def __init__(self, initlist: list = []):
self.data = initlist
class FiboList(UserList):
def __init__(self):
super().__init__([0, 1])
def __next__(self):
sum_ = sum(self.data)
self.data.append(sum_)
self.data.pop(0)
return sum_
def __iter__(self):
return self
# --- #
i = FiboList()
for number in i:
print(number)
@TheOnlyWayUp
Copy link
Author

Todos:

  • Make list predefined length of a maximum of Three Elements
  • Make list homogeneous (only of type int)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment