List vs Tuple vs Dictionary Comparison
Run the List vs Tuple vs Dictionary Comparison MicroSim Fullscreen
About This MicroSim
MicroPython gives you three ways to hold a group of related values, and they are not interchangeable. This infographic puts lists, tuples, and dictionaries side by side so you can tell them apart by three things: whether they can be changed, what brackets they use, and how you reach a value inside them. Your goal is to differentiate the three types, then decide which one fits a short robot-face scenario. Pick the wrong one and you either invite a bug, or write awkward code that fights the data.
How to Use
- Read the three columns from left to right and compare the Changeable? and Access by rows.
- Click any column header to expand a short "why you would choose this one" explanation.
- Read the scenario in the Try a Scenario panel and pick List, Tuple, or Dictionary.
- Watch the column outline turn green for correct or red for incorrect, and read the rule that decided the answer.
- Click Next Scenario to work through all six scenarios.
Iframe Embed Code
You can add this MicroSim to any web page by adding this to your HTML:
1 2 3 4 | |
Lesson Plan
Grade Level
9-12 (High School)
Duration
10-15 minutes
Prerequisites
- Knowing that a variable stores a value your program can use later, from earlier in Chapter 3
- Having seen the
expressionslist,eye_colortuple, andhappy_facedictionary examples in Chapter 3 - Understanding that MicroPython counts positions starting at 0, from earlier in Chapter 3
- Knowing that a display has a fixed pixel width and height, from Chapter 1
Activities
- Exploration (5 min): Compare the three columns and write down the one property that separates a tuple from a list, and the one property that separates a dictionary from both.
- Guided Practice (5 min): Click all three column headers to expand the explanations. For each type, write a robot-face example of your own that it would suit.
- Assessment (5 min): Work through all six scenarios without looking back at the columns. For each answer you get wrong, write down which rule you missed: mutability or access method.
Assessment
- The student states that a tuple cannot be changed after it is created, while lists and dictionaries can.
- The student states that lists and tuples are accessed by position, while dictionaries are accessed by key name.
- The student answers at least five of the six scenarios correctly.
- The student justifies each scenario choice by naming either mutability or access method, not by guessing.
References
- MicroPython Documentation - Official reference for the MicroPython language used throughout this book.
- Python Data Structures Tutorial - The standard Python guide to lists, tuples, and dictionaries.
- List (abstract data type) - Wikipedia - Background on ordered collections in computer science.
- Associative array - Wikipedia - The general idea behind key-value lookup, which dictionaries implement.