The big ideaA dictionary holds pairs, and you look up a key to get its value.
How it works
A dictionary is a collection of key and value pairs. You look up a key to get its value.
No counting boxes and no searching: the key leads straight to its value.
Each key may appear only once, or the lookup is unclear.
Add more columns and a dictionary becomes a table, with one row for each key.
A list, or a dictionary?
Example 1: Look up a key
Ravi writes each snack beside its price: apple 1 coin, cookie 2, juice 3 and soup 4.
Each snack is a key, and its price is the value in its pair.
Give it the key juice, and it hands back the value 3 coins.
Example 2: Each key once
Ravi adds a giant cookie and names it cookie too.
Now two rows are called cookie, so which price does the key mean?
The mix-up to fix: rename the new one giant cookie, which costs 5 coins.
Example 3: A table
Snack, price and how many are left are three columns.
Each row is one record, and there is one row for each snack.
Example 4: A word book
A word book works like a dictionary.
A word is the key, and its meaning is the value.
You look up the word and read its meaning.
Words to know
dictionary
A collection of key and value pairs.
key
The thing you look up, like a snack.
value
What you get back, like its price.
table
A dictionary with more columns, one row for each key.
record
One row of a table.
Watch out
The key is what you look up, and the value is what comes back.
Two keys with the same name make the lookup unclear.
If the order matters, like the steps to wash hands, a list fits better.
A dictionary needs no counting of boxes.
Try it
In the cafe table, is juice the key or the value?
What value does the key soup give back?
Can two keys be named cookie?
Do racers in finishing order fit a list or a dictionary?
Cookie costs 2 coins and giant cookie costs 5. How many more coins is the giant cookie?
Answers: 1. The key · 2. 4 coins · 3. No · 4. A list · 5. 3
Try at homeWrite the names of five family members or pets down one side of a paper and a favourite food or colour beside each. Ask a grown-up to say a name. You look it up and read the answer. Is any name used twice? What would you do?
For grown-upsDo the lookup Mission: write five names down one side of a paper and a favorite food beside each, then say a name for your child to look up. Ask what they would do if a name were used twice.
Open these notes on screenScan the code, or go to tutorpip.com.