Hiring Partners
Segilola Resources Operating LimitedTaviatech TechnologiesFCMBMTN NigeriaAdvans La Fayette Microfinance BankAboki AfricaFirst Bank of NigeriaOPay
← PYTHON FUNDAMENTALS LEVEL ONE PROFESSIONAL Β· Lesson 6 of 8

Module Five

πŸ“– Every lesson in this course is free to read right here, no account needed. Create a free account to track your progress, take the exam, and earn your certificate.
6
Module 5 Β· Data Structures Β· Python for 13-year-olds

πŸ—‚οΈ Module 5 Β· Data Structures

πŸ§‘β€πŸŽ“ for 13-year-olds store lots of data Β· 55 min
πŸ“‹ list Β· tuple Β· dict Β· set

So far, each variable held one thing. But what if you want to store your whole friend list, all your high scores, or a pet’s stats? That’s where data structures come in! πŸŽ’ Think of them as different kinds of containers β€” some are like a list of items, some are like labelled drawers. Let’s meet the four big ones.

1

Lists: your go-to container πŸ“‹

A list holds many items in order, inside square brackets [ ]. You can add, remove, and change items. Items can be any type β€” even other lists!

πŸŽ’ A list of snacks

"chips" "cookies" "apple" "popcorn"
index 0 β†’ "chips"  Β·  index 1 β†’ "cookies"  Β·  ...
snacks = ["chips", "cookies", "apple"]
print(snacks[0]) # chips
snacks.append("popcorn") # add to end
snacks[1] = "brownie" # change item
print(snacks) # ['chips', 'brownie', 'apple', 'popcorn']
MethodWhat it does
append(x)Adds x to the end
remove(x)Removes the first x
pop()Removes & returns the last item
sort()Sorts the list
len(list)How many items (also works on strings!)
πŸ’‘ Index starts at 0! The first item is snacks[0], not snacks[1]. Negative indexes count from the end: snacks[-1] = last item.
2

Tuples: the locked list πŸ”’

A tuple looks like a list but uses parentheses ( ), and it can’t be changed after it’s created. It’s perfect for things that should stay fixed, like coordinates or a birthdate.

πŸ—ΊοΈ A coordinate point

10 , 25 (x, y) β€” fixed forever
point = (10, 25)
print(point[0]) # 10
# point[0] = 99 ← ❌ ERROR: tuple can't be changed

# Handy unpacking:
x, y = point
print(x + y) # 35
🧠 Why bother? Tuples tell other programmers β€œthis shouldn’t change.” They’re also faster than lists.
3

Dictionaries: labelled drawers πŸ—„οΈ

A dictionary stores key β†’ value pairs inside curly braces { }. Instead of using an index number, you look things up by a key (like a name or label). Super useful for real-world data!

πŸ• A pet’s info

"name" β†’ "Rex"
"age" β†’ 4
"tricks" β†’ ["sit", "roll over"]
pet = {"name": "Rex", "age": 4, "tricks": ["sit", "roll over"]}
print(pet["name"]) # Rex
pet["age"] = 5 # change a value
pet["colour"] = "brown" # add a new key
print(pet.keys()) # dict_keys(['name', 'age', 'tricks', 'colour'])
MethodWhat it does
pet["name"]Get a value by key
pet.get("age")Safe lookup (won’t crash if key is missing)
pet.keys()All the keys
pet.values()All the values
pet.items()Both, as pairs
πŸ”‘ Keys must be unique. If you use the same key twice, the last value wins. Keys are usually strings, but can be numbers too.
4

Sets: no duplicates allowed 🎯

A set is an unordered collection with no duplicates. It’s great for removing repeats or checking if something exists fast. Use curly braces { } (but no key: value pairs).

🎨 Unique favourite colours

"blue" "red" "green"
Adding "blue" again β†’ still just 3 items βœ…
colours = {"blue", "red", "green"}
colours.add("blue") # no effect β€” already there!
colours.add("yellow") # now 4 colours
print("red" in colours) # True (super fast check)

# Remove duplicates from a list:
votes = ["yes", "no", "yes", "yes"]
print(set(votes)) # {'yes', 'no'}
🚫 No order: Sets don’t keep items in a particular order, so you can’t use indexes like [0].
5

List comprehensions: supercharged loops ⚑

A list comprehension builds a new list in one line using a mini for loop. It’s a favourite Python trick β€” short, readable, and powerful.

# Old way (works fine!)
squares = []
for n in range(1, 6):
squares.append(n * n)

# List comprehension way (one line!)
squares = [n * n for n in range(1, 6)]
print(squares) # [1, 4, 9, 16, 25]

# With a filter:
evens = [n for n in range(1, 11) if n % 2 == 0]
print(evens) # [2, 4, 6, 8, 10]
πŸ§ͺ Read it like English: β€œ[n * n] for each n in range(1,6)” β†’ β€œgive me nΓ—n for each n from 1 to 5.”
6

Which one should I use? πŸ€”

Each structure has a personality. Here’s a quick cheat sheet:

StructureBest forCan change?Ordered?
πŸ“‹ ListA collection of items (friends, scores)βœ… Yesβœ… Yes
πŸ”’ TupleFixed data (coordinates, dates)❌ Noβœ… Yes
πŸ—„οΈ DictLook things up by name/keyβœ… Yesβœ… Yes (Python 3.7+)
🎯 SetUnique items, fast membership checksβœ… Yes (add/remove)❌ No
🧠 Starter rule: When in doubt, use a list. Switch to a dict when you need labels, and a set when you need uniqueness.

πŸ† Mini challenge: Your dream playlist

Create a file called playlist.py. Build a program that uses all four data structures:

  • A list of your 5 favourite songs (strings).
  • A tuple for your favourite artist’s (name, debut year).
  • A dictionary describing one song: title, artist, length in seconds.
  • A set made from a list with duplicates, to show how it removes them.
  • Print everything β€” try using a list comprehension to make a list of song titles in ALL CAPS.
# Starter code – fill in your own favourites!
songs = ["Song A", "Song B", "Song C"]
top_artist = ("Artist X", 2015)
song_info = {"title": "Song A", "artist": "Artist X", "seconds": 210}
duplicate_songs = ["Song A", "Song B", "Song A"]

# Your code here – print, loop, and use a comprehension!

🎧 Bonus: use a for loop to print each song with its index number, and use .items() to print the dictionary neatly.

πŸ§‘β€πŸ« Remember: Lists use [ ], tuples use ( ), dicts & sets use { }. Try creating each one and printing type() to compare!

πŸ† Get Certified

πŸ”’

Earn this certificate

Every lesson is already free to read. Sign up, finish the lessons, pass the exam (₦2,000 or 20,000 coins), and get a verified certificate with your name on it.

πŸŽ“ Sign Up to Get Certified
πŸ› οΈ Practice Tools
Hands-on simulators & labs - subscription required.
β†’
🎯 Internship Tasks
Real-world tasks to build your portfolio - unlock them with a subscription.
β†’