Working with dictionaries
So far, you've added the ingredients with their quantities in grams.
Now, you want to practice accessing the dictionary's contents using different methods to confirm the dictionary is set up as expected, and to prepare for scaling later on.
Deze oefening maakt deel uit van de cursus
Introduction to Python for Developers
Oefeninstructies
- Use a method to retrieve all the keys from the
recipedictionary and assign the result toingredient_names. - Use a method to retrieve all the values from the
recipedictionary and assign the result toquantities. - Use a method to retrieve all key-value pairs from the
recipedictionary and assign the result torecipe_items.
Praktische interactieve oefening
Probeer deze oefening eens door deze voorbeeldcode in te vullen.
# Get all ingredient names
ingredient_names = ____
# Get all quantities
quantities = ____
# Get all key-value pairs
recipe_items = ____
print("Ingredient names:", ingredient_names)
print("Quantities:", quantities)
print("Recipe items:", recipe_items)