What Are Dictionaries?

STEP 1 — What Are Dictionaries?

(a.k.a. Giving Your Game Items Actual STATS Instead of Vibes)

Up until now, your game items have been… well… kind of mysterious.

A sword was just “Sword”.
A potion was just “Potion”.
A banana was… still a banana.

But real games don’t work like that.

A sword has damage.
A potion has healing.
A banana has… questionable nutritional value.

You need a way to store multiple pieces of information about one thing.

And that’s where dictionaries come in.


1. What Is a Dictionary?

A dictionary is a Python structure that stores data in key–value pairs.

Think of it like a labeled box:

  • “name” → “Sword”
  • “damage” → 10
  • “rarity” → “Common”
Here’s what it looks like in code:
weapon = {
    "name": "Sword",
    "damage": 10,
    "rarity": "Common"
}

print(weapon)

Boom.

Your sword now has stats, identity, and purpose.

It’s basically a LinkedIn profile for your game items.

Click Run

2. Keys and Values (The Dynamic Duo)

A dictionary has:

  • Keys → the labels
  • Values → the data

Example:

player = {
    "name": "Aria",
    "health": 100,
    "level": 3
}

print(player["name"])
print(player["health"])
print(player["level"])

Keys: “name”, “health”, “level”
Values: “Aria”, 100, 3

It’s clean.
It’s organized.
It’s everything your code has been begging for.

Click Run

3. Why Games LOVE Dictionaries

Dictionaries let you build:

  • player profiles
  • enemy stats
  • item attributes
  • NPC data
  • shop items
  • quest information
  • settings menus

Basically, if it has stats, properties, or details, it belongs in a dictionary.


Practice (Your Turn!)

Mini-Challenge #1

Create a dictionary called enemy with:

  • name
  • health
  • attack

Give it any values you want.

Modify and Run

Mini-Challenge #2

Create a dictionary called potion with:

  • type
  • healing amount
  • rarity
Modify and Run