✨
I'm Kevin
@kevteg
@keeevinh
Any object that implements the next method, that is, an object that you can iterate over
next
A "lazy" iterator, that is, the value is calculated during the iteration
import time def fibonacci(): '''Good old fibonacci''' a, b = 0, 1 while True: yield b # Sleep to be able to see the numbers generation time.sleep(1) a, b = b, a+b
cool_iterator = (n for n in range(1000000000))
def coroutine(): # dumb coroutine example x = 0 while True: x = (yield x) + x
https://www.python.org/dev/peps/pep-0255/
http://www.dabeaz.com/coroutines/
Serious Python book
https://github.com/kevteg/generators-examples
❤️ 🐍
By Kevin Hernández
CS engineer. Python dev, docker fan.