Created
October 24, 2016 14:17
-
-
Save EdisonChendi/f05b64dd4ced55d4243e7215f3d9e2d8 to your computer and use it in GitHub Desktop.
python lazy evaluation
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
# coding=utf-8 | |
from itertools import islice | |
def fib(): | |
a, b = 0, 1 | |
while True: | |
yield a # lazy evaluation | |
a, b = b, a+b | |
print(list(islice(fib(), 10))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment