Level 7: Dictionaries - IncrediCoders/Python1 GitHub Wiki

Syntax Turtle added this page on June 6, 2025


Here is a bonus article that will tell you more about Dictionaries!

In addition to this bonus article, you can find other bonus articles that teach you the topics I covered in Level 7: Classes and Sets.

Learn About Dictionaries

A dictionary in programming is like a real-life dictionary—it stores keys and their values. In code, it helps you match one thing to another, like a name to a phone number or a student to a grade. Instead of using a list with just numbers, a dictionary lets you label things. You can also add, change, or remove things in a dictionary.

[TO DO: What is the relationship between Dictionaries and State Machines?]

Why Dictionaries Matter

Dictionaries are helpful when you want to look something up quickly. Instead of guessing where something is, you just ask for it by name, just like looking for a word in a real dictionary.

Python Example

In Python, you make a dictionary using curly braces {}, with keys and values separated by a colon.

Scenario: Paul Python wants to remember each friend’s favorite fruit.

favorite_fruits = {
    "Grafika Turtle": "Apple",
    "Annie Conda": "Banana",
    "Bayo Wolf": "Grapes"
}

# Let's find out what Annie Conda likes
print(favorite_fruits["Annie Conda"])

This will print: Banana because that’s Annie Conda’s favorite fruit.

Comparing Programming Languages

Dictionaries exist in many languages, but they might have different names, like “maps” or “hash tables.”

Scenario: Let’s store the favorite colors of Paul Python and Grafika Turtle.

Python

favorite_colors = {
    "Paul Python": "Blue",
    "Grafika Turtle": "Green"
}

Java

import java.util.HashMap;

HashMap<String, String> favoriteColors = new HashMap<>();
favoriteColors.put("Paul Python", "Blue");
favoriteColors.put("Grafika Turtle", "Green");

C#

using System.Collections.Generic;

Dictionary<string, string> favoriteColors = new Dictionary<string, string>();
favoriteColors["Paul Python"] = "Blue";
favoriteColors["Grafika Turtle"] = "Green";

What’s the Difference?

  • Python uses simple curly braces {} and colons :.
  • Java and C# require more setup and use HashMap or Dictionary.
  • All three let you store key–value pairs so you can look up information fast.

Learn More

TBD

Next Steps

Next, you can take on the two extra challenges to build more features for the IncrediCards game, and to learn more!

Take the Challenges!

  1. Challenge 1: In this challenge, you are going to add two more cards to each player's deck, so that you can switch between five cards (instead of three cards).

  2. Challenge 2: In this second challenge, you are going to add a second attack option, the Coded Attack (which has special abilities, like to get an extra turn).

More Level 7 Resources

  • Level 7: Unplugged Activity - I wrote this page with more details than what you saw in the book. In this game,

  • Level 7: Rewards - If you completed the IncrediCards program that we talked about, then I set up this page to act as a reward. You can see some illustrations of me and learn more about who I am! You'll also find the WHAT Award digital download, to show off your accomplishment!

  • Level 7: IncrediCards - All Online Resources - Return back to the main Level 7 page, with all our online resources!

Level 7

After you're completely done with Level 6 (did you do the challenges?), then it's time to move on to Level 7! While you read through Level 7 in your book, you can check out the resources from CHARACTER, as he teaches you how to build the IncrediCards program:

Syntax and I love to make card games like IncrediCards! We hope you had fun learning about it too!

--Grafika and Syntax Turtle

⚠️ **GitHub.com Fallback** ⚠️