Programming fundamentals›Dictionaries and sets
Tutorial 7 of 13 · Programming fundamentals · Collections and text · BeginnerDictionaries and sets
Look things up by name instead of by position, and keep a collection with no repeats.
5 lessons, the last is a challenge · 55 min · Python and Java
Before you startYou finished "Lists": you can make a list, read a value by its position, and go through a list with a loop.
What you’ll be able to do
- 1Make a dictionary of pairs, read a value by its key, and say what you get back when the key is not there.
- 2Add a pair, change a value, take a pair out, and say what the dictionary holds afterwards.
- 3Count things with a dictionary: one loop that adds one to the count of each word it meets.
- 4Use a set to keep each value once and to ask whether a value has been seen, and choose between a list, a dictionary and a set for a job.
Lessons
- 1Looking things up by nameMake a dictionary and read a value by its key, with a fallback for a key that is not there.12 min, up next
- 2Adding, changing, removingPut a pair in, change a value, take a pair out, and say what a missing key does.11 min
- 3Counting with a dictionaryWrite the five-line loop that counts how often each word appears.12 min
- 4SetsKeep each value once, ask whether a value has been seen, and pick the right shape for a job.10 min
- 5Final challenge: count it and look it upFinal challenge · Predict, complete, fix and choose, with dictionaries and sets.10 min
Next in this path
Next: 8 · Nested data · 5 lessons · 55 min
Lists inside dictionaries and dictionaries inside lists: how real data is shaped, and how to reach into it.
Playground
Try the same model with your own values. No checks, nothing recorded.
Open the playground