Skip to content

Instantly share code, notes, and snippets.

@alairock
Last active August 14, 2018 16:58
Show Gist options
  • Save alairock/1e222f30b75531e4dd74b3b79e0c2533 to your computer and use it in GitHub Desktop.
Save alairock/1e222f30b75531e4dd74b3b79e0c2533 to your computer and use it in GitHub Desktop.
import time
# Everyone in queue, and their desired order
customers = [('Bob', 'Ham Sandwich'), ('Paul', 'Grilled Cheese'), ('Sally', 'Chicken Croissant')]
# make a sandwich, but pause(yield) to deliver it
def make_sandwiches():
for customer in customers:
time.sleep(1) # making the sandwich for our customer
yield (customer[0], customer[1])
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