Skip to content

Instantly share code, notes, and snippets.

@EdisonChendi
Created October 24, 2016 14:17
Show Gist options
  • Save EdisonChendi/f05b64dd4ced55d4243e7215f3d9e2d8 to your computer and use it in GitHub Desktop.
Save EdisonChendi/f05b64dd4ced55d4243e7215f3d9e2d8 to your computer and use it in GitHub Desktop.
python lazy evaluation
# 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