Skip to content

Instantly share code, notes, and snippets.

@alairock
Last active July 31, 2018 16:19
Show Gist options
  • Save alairock/773a89ced3b61b1e409681a22f9f472a to your computer and use it in GitHub Desktop.
Save alairock/773a89ced3b61b1e409681a22f9f472a to your computer and use it in GitHub Desktop.
Generator Next
import time
def make_sandwich(customers):
for customer in customers:
time.sleep(1) # let's pretend this is the time it takes to make the sandwich
yield customer
maker = make_sandwich(['Bob', 'Paul', 'Sally'])
print('Just made a sandwich for:', next(maker))
print('Just made a sandwich for:', next(maker))
print('Just made a sandwich for:', next(maker))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment