Created
September 7, 2021 22:12
-
-
Save subzero112233/73a7536a92a35f03b6029e143115baf4 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
def fib(n): | |
a, b = 0, 1 | |
for _ in range(n): | |
yield a | |
a, b = b, a + b | |
k = fib(10) | |
>>> next(k) | |
0 | |
>>> next(k) | |
1 | |
>>> next(k) | |
1 | |
>>> next(k) | |
2 | |
>>> next(k) | |
3 | |
>>> next(k) | |
5 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment