Editor

Find Missing Ingredients

Intermediate · Write the code · from Python Sets: Unique Collections, Operations, and Use Cases

From the lesson: Python Sets: Unique Collections, Operations, and Use Cases

Imagine you're a teacher taking attendance. A student accidentally signs the attendance sheet twice. Does that mean they're in class twice? Of course not. You only care about who showed up, not how many times they wrote their name.

Read the lesson

You have a recipe set with all required ingredients and a pantry set with what you already have. Find the ingredients you still need to buy and print them as a sorted list.

recipe = {'flour', 'sugar', 'eggs', 'butter', 'vanilla'}
pantry = {'flour', 'eggs', 'salt', 'pepper'}
# Find and print what you need to buy (sorted)

More Sets exercises

All Python exercises · 50 practice problems · Data Structures quiz