Have you ever used a real dictionary to look up a word? You find the word, and right next to it is its meaning. Super handy, right? Well, guess what? Computers have their very own kind of dictionary too! In coding, a dictionary is a special way to store information so it is easy to find later. Today, we are going on an adventure to learn what dictionaries are, how they work, and how you can use them in your own code. Ready? Let’s go!
What Is a Dictionary in Coding?
A dictionary in coding is a way to keep information in pairs. Each pair has two parts:
- A key – this is like the word you look up.
- A value – this is like the meaning or answer that goes with the key.
Together, we call them a key-value pair. Just like you look up the word “apple” to find out what it means, a computer looks up a key to find its value.
A Simple Example of a Dictionary
Imagine you want to remember your friends’ favorite colors. You could make a dictionary like this:
- Key: “Mia” → Value: “purple”
- Key: “Leo” → Value: “green”
- Key: “Sam” → Value: “blue”
Now, if you want to know Leo’s favorite color, you just look up “Leo” and the computer tells you “green”. Easy peasy!
How Do Dictionaries Look in Real Code?
Many programmers use a language called Python. Here is what our favorite colors dictionary looks like in Python:
favorite_colors = {"Mia": "purple", "Leo": "green", "Sam": "blue"}
Let’s break it down:
- The curly brackets
{ }tell the computer, “Hey, this is a dictionary!” - The colon
:connects a key to its value. - The commas
,separate each pair.
Looking Up a Value
To find Mia’s favorite color, you write:
print(favorite_colors["Mia"])
The computer will show: purple. It’s like asking your dictionary a question and getting the answer right away!
Fun Things You Can Do With Dictionaries
Dictionaries are not just for looking things up. You can change them too! Here are some cool tricks:
Adding a New Pair
Got a new friend named Zoe who loves yellow? Add her like this:
favorite_colors["Zoe"] = "yellow"
Changing a Value
Did Sam change his mind and now loves red? No problem:
favorite_colors["Sam"] = "red"
Removing a Pair
If you want to take someone out of the dictionary, you can use:
del favorite_colors["Leo"]
Why Do Programmers Love Dictionaries?
Dictionaries are one of the most useful tools in coding. Here’s why:
- They are fast: Computers can find a value super quickly using its key.
- They keep things organized: Information is neat and easy to understand.
- They use names, not numbers: Instead of remembering positions like in a list, you use easy names as keys.
- They are everywhere: Games, apps, and websites use dictionaries all the time!
Dictionaries in Everyday Life
You already use dictionary-like ideas every day without knowing it! Check out these examples:
- A phone contact list: A name (key) goes with a phone number (value).
- A video game character: “health” might be 100 and “power” might be 50.
- A school locker: Each student’s name goes with a locker number.
- A menu: Each food item goes with its price.
Try It Yourself: Build a Pet Dictionary
Here is a fun challenge! Make a dictionary about your pet or a pet you wish you had:
my_pet = {"name": "Buddy", "type": "dog", "age": 3}
Can you add a key called “favorite_toy”? Give it a try!
Dictionary vs. List: What’s the Difference?
You might have heard about lists in coding too. Here’s how they are different:
- Lists keep items in order, and you find them by their position number (like 0, 1, 2).
- Dictionaries keep items in pairs, and you find them by their key name.
Think of a list like a line of kids waiting for lunch, and a dictionary like name tags on lunchboxes!
Conclusion: You’re Now a Dictionary Expert!
Awesome job, coder! Today you learned that a dictionary in coding stores information in key-value pairs, just like a real dictionary matches words with meanings. You also learned how to create, look up, add, change, and remove items. That’s a big step on your coding journey!
Want to learn more cool coding words? Follow our Coding Terms Explained for Kids series so you never miss a new post. Next time, we’ll explore another exciting coding term. Keep coding, keep exploring, and have fun!arn more? Stay tuned for our next post, where we’ll explore another cool coding term! Don’t forget to follow our series!


