Skip to content

Instantly share code, notes, and snippets.

@ZhouYang1993
Created May 28, 2020 21:04
Show Gist options
  • Save ZhouYang1993/204dea5772923d13d6b69abbb2df61d6 to your computer and use it in GitHub Desktop.
Save ZhouYang1993/204dea5772923d13d6b69abbb2df61d6 to your computer and use it in GitHub Desktop.
from collections.abc import Iterable, Iterator
def Fib(max):
n, a, b = 0, 0, 1
while n < max:
yield b
a, b = b, a + b
n = n + 1
return 'done'
f = Fib(10000)
print(isinstance(f, Iterator))
print(next(f))
print(next(f))
print(next(f))
print(next(f))
# True
# 1
# 1
# 2
# 3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment