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 lessonYou 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
- Remove Duplicates from a ListBeginner
- Predict the Set OutputBeginner
- Find Students in Both ClassesIntermediate
- Fix the Empty Set BugIntermediate
- Deduplicate While Preserving OrderAdvanced
All Python exercises · 50 practice problems · Data Structures quiz