Preplp
Daily Python
Day 9Python~35 min

Tuples & Sets

Immutable sequences and unique collections

Track progress0/15 days
x

What you'll learn

tuplesetunionintersectiondifference
  • Unpack tuples and use set operations
  • Compare recipe vs pantry ingredients

Lesson & examples

Read the code, then the explanation — try changing values before the project.

Set operations
a = {"flour", "sugar", "butter"}
b = {"sugar", "eggs"}
print(a - b)  # missing from b
print(a & b)  # in common

Today's exercise: Ingredients Checker

Check which recipe ingredients the user is missing.

Steps

  1. 1

    Recipe set

    Define recipe_ingredients as a set.

  2. 2

    Compare

    Parse user input into a set and use difference.

Full project source — copy into a folder or use the zip above

starter.py
recipe_ingredients = {"flour", "sugar", "butter", "eggs", "milk"}

user_input = input("Enter ingredients you have (comma-separated): ")
user_ingredients = {i.strip() for i in user_input.split(",") if i.strip()}

missing = recipe_ingredients - user_ingredients
extra = user_ingredients - recipe_ingredients

print("\n--- Ingredient Check ---")
if missing:
    print("Missing:", ", ".join(missing))
else:
    print("You have everything!")
if extra:
    print("Extra:", ", ".join(extra))

One rehearsal platform

Certification mocks, daily lessons, project labs, and in-browser drills

Structured for exam day and portfolio proof — timed tests, guided builds, and quick reps on one platform.