Buckle up, because today’s class is about to turn into an all-out Super Smash Bros. brawl—code style! You’ve already mastered snagging heroes in dictionaries and powering up Pokémon cards, but now it’s time to step onto the stage with Mario, Link, and the gang!
Picture this: your roster’s a dictionary stuffed with fighters, moves, and stats, and you’re the ultimate Smash strategist. We’re gonna loop through every corner of that roster—nabbing names, scoping moves, and dodging errors like a pro dodging a Final Smash. Whether you’re scouting your mains, sorting the lineup, or counting killer punches, you’ll be the champ of this dictionary battlefield. Grab your imaginary Joy-Cons, pick your fighter, and let’s loop our way to victory—Smash style!
Because there may be a large amount of data, Python gives us a mechanism to go through it all. And, Since Dictionaries can be stored in a variety of ways, there are several different ways to loop through them which we'll look at...
.items( )
.keys( )
.values( )
.set( )
Before we begin looking at dictionary looping, we are going to need to do some setup.
You'll need to create a new dictionaries and code listed here
All of these can be hard-coded
items() gives us both the fighter (key) and move (value)
Once we have all of the key-value pairs, the for loop moves through each of them!
keys() allows us to loop through ONLY the keys
This does NOT give you values!!
This is useful if we want to display keys to search like in a menu, so users don't have to try and remember all the keys
sorted() sorts the dictionary alphabetically by first key (A-Z)
values() allows us to loop through ONLY the values, without worrying about what the key for each one is
In our example, it will show all moves, repeats included
set( ), in our example, will loop through UNIQUE MOVES ONLY
set() cuts duplicates—if two fighters had ‘Punch,’ we’d only see it once!
Only because we've seen these, let's look at an example which raises an exception!!
“If we try to grab a stat that’s not there—like ‘speed’—we get a KeyError
You'll need these dictionaries to begin your challenges!
You’ve trained your fighters. You’ve powered up their stats. But now it’s time to put your coding skills to the ultimate test in the Stat Showdown Arena!
Today, you’re taking control of a Smash Bros. roster—and the crowd’s going wild! They want hype. They want drama. They want you to loop through every last stat and reveal the champions of the battlefield.
On the screen is your Mission Board, filled with coding challenges that’ll push your skills in looping through dictionaries. Each mission unlocks new powers—printing wild stat sheets, customizing fighter abilities, discovering rare moves, and even dodging deadly KeyError traps.
🔁 items() – Show off full stat sheets
🧠 keys() – Help the crowd pick what to update
🧾 sorted() – Organize the chaos
🎯 values() – Unleash signature moves
🌍 set() – Reveal unique universes
⚠️ try/except – Defend against Smash crashes
⚠️ Reminder: This isn’t about repeating Day 1 or Day 2—today is Level 3. Use what you’ve learned, but this is new terrain. You’ll be managing teams, customizing stats, and looping like a Smash master.
You can tackle these in any order. Go solo or tag-team with a buddy. But whatever you do—get coding and make your fighters shine. The arena awaits.
🎤 "Welcome to the Smash Arena!"
Loop through each fighter with .items() and display all stats.
Goal: Use .items() with personality
Bonus: Add a pause() using time.sleep() to slow the reveals
Make sure the user can select multiple characters to display! Not just one and done!
🕵️♂️ "Pick a fighter and update their stat using the available keys!"
Use .keys() to display stat options for one fighter.
Let user pick a stat and update it (e.g., increase power, change move).
Goal: Use .keys() to guide input instead of hardcoding
🔍 "Show the fighter’s stats alphabetically for review."
Ask for a fighter name and use sorted() to print their stats in alphabetical order (key only).
Goal: Combine .keys() with sorted() and input()
Bonus: Use .title() to make display cleaner
💥 "Let’s see everyone’s best moves!"
Loop through all fighters and print their 'move' values using .values().
Goal: Loop through nested dictionaries to collect specific values
Extension: Ask user for a stat they want to see across all fighters (not just moves)
🌍 "What worlds are represented today?"
Use set() to extract all unique 'series' values from the team.
Goal: Use set() to find non-repeating stat values
Bonus: Let user choose a stat to analyze with set() (e.g., all unique powers, speeds, etc.)
🔥 "Attempt to show a nonexistent stat and survive the crash!"
Let user type a stat name to retrieve from a fighter. Use try/except to catch a KeyError.
Goal: Reinforce safe error handling with .get() or try/except
Build a full Smash Fighter Manager program that:
Lets the user add new fighters
Allows stat updates
Loops and compares specific stats (e.g., who has the highest power?)