“Sometimes you don’t want just one variable. You want a bunch. Neatly stacked. Organized. Possibly with labels. Like sushi. Or trauma.”
So far, you’ve been feeding your code little bites: one variable at a time.
snack1 = "apple"
snack2 = "chips"
snack3 = "sad granola bar"
Stop. You deserve better. We all do.
Meet lists and dictionaries: your way to bundle and organize all that data, so your functions don’t become hoarders with no filing system.
A list is like a container. A box of things. It can hold:
snacks = ["apple", "chips", "sad granola bar"]
You can:
snacks[0]
→ "apple"snacks.append("cookie")
snacks.pop()
# Make a list of your top 5 favorite movies
# Print each one with its ranking
Let Cursor handle the loop logic. You handle the popcorn.
snacks = ["banana", "peanut", "tuna"]
print(snacks[0]) # banana
for snack in snacks:
print("Delicious:", snack)
Or:
for i in range(len(snacks)):
print("Item #" + str(i + 1) + ":", snacks[i])
Loops + lists = code that scales like a wizard elevator.
Let’s say you want to store not just items, but meanings:
snack_info = {
"apple": "healthy",
"chips": "salty",
"sad granola bar": "emotional support"
}
A dictionary (or dict
) is a collection of key-value pairs.
print(snack_info["chips"]) # Output: salty
snack_info["cookie"] = "delightful mistake"
for snack, vibe in snack_info.items():
print(snack, "is", vibe)
Data Type | Real World Analogy |
---|---|
list |
A box full of unlabelled stuff |
dict |
A library where each item has a label |
Index | A position in line |
Key | A name tag on a drawer |
# Create a dictionary of planets and their number of moons
# Print each planet and say whether it’s "moon rich" or "moon poor"
Cursor will likely loop through your dictionary like a proud astrologer.
Add drama:
Use a dictionary for questions and answers.
# Ask Cursor to:
# - Create 3 questions and answers in a dictionary
# - Loop through them and ask the user
# - Track the score and give a final grade
Then:
menu = {
"breakfast": ["eggs", "pancakes"],
"lunch": ["sandwich", "soup"],
"dinner": ["sushi", "pizza"]
}
Access like:
print(menu["lunch"][1]) # soup
It’s turtles all the way down. But tasty turtles. 🐢
# Create a to-do list app that uses a list of dictionaries
# Each task should have a name, priority, and status
# Add functions to display, add, and mark complete
Now you’re building software, not just code.