×

python · level 2 · unit 1 · lesson 2

  1. meet it
  2. guess first
  3. your turn
  4. fix it
  5. nailed it

Tap a green word if you get lost.

meet it

Dictionaries are : add, replace and remove pairs.

A dictionary is mutable, which means you can change it after you make it. Store a value under a new key and a pair is added. Store a value under a key that already exists and its old value is replaced.

removes the milk pair completely. len(basket) counts the pairs.

Before you look something up, you can ask first. "milk" in basket is True only when that key is there, and "milk" not in basket is the opposite.

basket = {"apples": 3, "milk": 1}
basket["bread"] = 1
basket["apples"] = 5
del basket["milk"]
print(basket)
print("milk" in basket)
print(len(basket))

in only checks the keys of a dictionary, never its values.