from itertools import dropwhile, takewhile, islice
def fibs():
a, b = 0, 1
while True:
yield a
a, b = b, a + b
for x in fibs():
print(x)
if x > 250:
break
print(list(islice(fibs(), 15)))
print(list(takewhile(lambda x: x < 250, \
dropwhile(lambda x: x < 8, fibs()))))
Item 7: Generator Function
Posted by Logan Chien