Last active
May 16, 2020 20:25
-
-
Save aniruddha27/69df9fd385f68a6133e2fa798ac22d41 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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