Last active
August 3, 2018 17:06
-
-
Save alairock/5a3377048a890374e23f3aa5fba4cba8 to your computer and use it in GitHub Desktop.
Generators
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 | |
# Everyone in queue, and their desired order | |
def get_customers(): | |
return [('Bob', 'Ham Sandwich'), ('Paul', 'Grilled Cheese'), ('Sally', 'Chicken Croissant')] | |
customers = get_customers() | |
# make the sandwiches for all the customers, then deliver | |
def make_sandwiches(): | |
completed_sandwiches = [] | |
for customer in customers: | |
time.sleep(1) # making the sandwich for our custoemr | |
completed_sandwiches.append((customer[0], customer[1])) | |
return completed_sandwiches | |
sandwiches = make_sandwiches() | |
# deliver the sandwiches | |
for sandwich in sandwiches: | |
print('Delivering sandwich:', sandwich[1], 'for', sandwich[0]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment