Introductie tot Python voor developers
Jasmin Ludolf
Senior Data Science Content Developer
ingredients = ["pasta", "tomatoes", "garlic", "basil", "olive oil", "salt"]# Hoeveelheden (in gram) quantities = [500, 400, 15, 20, 30, 5]

usernameemailpreferences
ip_addresslocation$$


# Een dictionary maken
recipe =
# Een dictionary maken
recipe = {
# Een dictionary maken
recipe = {"pasta"
# Een dictionary maken
recipe = {"pasta":
# Een dictionary maken
recipe = {"pasta": 500
# Een dictionary maken
recipe = {"pasta": 500,
# Een dictionary maken
recipe = {"pasta": 500,
"tomatoes": 400,
# Een dictionary maken
recipe = {"pasta": 500,
"tomatoes": 400,
"garlic": 15,
"basil": 20,
"olive oil": 30,
"salt": 5
# Een dictionary maken
recipe = {"pasta": 500,
"tomatoes": 400,
"garlic": 15,
"basil": 20,
"olive oil": 30,
"salt": 5}
Dictionaries zijn geordend
Hoeveel pasta hebben we nodig?
# Zoek de hoeveelheid van het ingrediënt
print(recipe["pasta"])
500
# Alle waarden uit een dictionary halen
print(recipe.values())
dict_values([500, 400, 15, 20, 30, 5])
# Alle keys uit een dictionary halen
print(recipe.keys())
dict_keys(['pasta', 'tomatoes', 'garlic', 'basil', 'olive oil', 'salt'])
# Print de dictionary
print(recipe)
{'pasta': 500, 'tomatoes': 400, 'garlic': 15, 'basil': 20, 'olive oil': 30,
'salt': 5}
# Alle items (key-valueparen) ophalen
print(recipe.items())
dict_items([('pasta', 500), ('tomatoes', 400), ('garlic', 15), ('basil', 20),
('olive oil', 30), ('salt', 5)])
# Een nieuw key-valuepaar toevoegen
recipe["parmesan"] = 50
print(recipe)
{'pasta': 500, 'tomatoes': 400, 'garlic': 15, 'basil': 20, 'olive oil': 30,
'salt': 5, 'parmesan': 50}
print(recipe)
{'pasta': 500, 'tomatoes': 400, 'garlic': 15, 'basil': 20, 'olive oil': 30,
'salt': 5, 'parmesan': 50}
# Een waarde bijwerken voor een bestaande key
recipe["pasta"] = 1000
print(recipe)
{'pasta': 1000, 'tomatoes': 400, 'garlic': 15, 'basil': 20, 'olive oil': 30,
'salt': 5, 'parmesan': 50}
# Een dictionary maken met een dubbele key recipe = {"pasta": 500, "garlic": 5, "garlic": 15, "basil": 20, "olive oil": 30, "salt": 5}# Print de waarde van de dubbele key print(recipe["garlic"])
15
Introductie tot Python voor developers