Last active
July 31, 2018 16:19
-
-
Save alairock/773a89ced3b61b1e409681a22f9f472a to your computer and use it in GitHub Desktop.
Generator Next
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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