Skip to content

Instantly share code, notes, and snippets.

@aniruddha27
Last active May 16, 2020 20:25
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 aniruddha27/69df9fd385f68a6133e2fa798ac22d41 to your computer and use it in GitHub Desktop.
Save aniruddha27/69df9fd385f68a6133e2fa798ac22d41 to your computer and use it in GitHub Desktop.
# fibonacci sequence using a generator
def fib():
prev, curr = 0, 1
# infinite loop
while prev<5:
value = prev
# Calculate the next number in the sequence. Using Tuple unpacking.
prev, curr = curr, prev + curr
# yield the value
yield value
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment