[1, 2, 3]
{"key": val}
append()
list[0]
.items()
len()
dict.get()
for x in
Unit 4 of 5

Collections

Single variables hold one value. Collections hold many β€” and that changes everything. Lists and dictionaries are the backbone of real programs.

5
Lessons
20
Challenges
1
Project
What You'll Learn

Skills Unlocked in This Unit

πŸ“‹

Create & Access Lists

Ordered sequences with indexing, slicing, and len().

✏️

Modify Lists

append(), insert(), remove(), pop() β€” lists are mutable!

πŸ”„

Iterate Over Lists

for item in list, enumerate(), search, filter, transform.

πŸ—‚οΈ

Dictionaries

Key-value pairs for labeled data: contacts, inventories, configs.

πŸ”

Dict Iteration

.keys(), .values(), .items() β€” loop through labeled data.

πŸ“±

Build an App

Combine everything into a full contact manager.

Quick Comparison

Lists vs Dictionaries

Two ways to organize data β€” choose based on how you'll look it up.

πŸ“¦ Side by Side

Reference

πŸ“‹ List β€” Ordered by Position

scores = [95, 87, 92, 78]
print(scores[0]) # 95 (first)
print(scores[-1]) # 78 (last)
scores.append(88) # add to end
print(len(scores)) # 5
βœ“ Great for: ordered sequences, things you access by position
βœ“ Items don't need labels β€” position IS the identifier

πŸ—‚οΈ Dict β€” Labeled by Key

student = {
  "name": "Alex",
  "grade": 95,
  "active": True
}
print(student["name"]) # Alex
βœ“ Great for: labeled data, lookups by name
βœ“ Each value has a meaningful key β€” like a real-world form
Lesson Roadmap

Your Path Through Unit 4

Click any lesson to see its challenges.

πŸ“‹

4.1 Lists: Creating & Accessing

4 challenges

Create lists, access elements by index (positive & negative), use len(), and slice to extract portions.

list syntaxindexingnegative indexlen()slicing
Challenges
Playlist Manager β€” access songs by index
First and Last β€” negative indexing
Middle Finder β€” handle odd/even lengths
Slice Explorer β€” first 3, last 3, every-other
Start Lesson β†’
✏️

4.2 Modifying Lists

4 challenges

Add, remove, and rearrange list items with append(), insert(), remove(), pop(), and the in keyword.

append()insert()remove()pop()inmutable
Challenges
Shopping List β€” append and remove
Queue Simulator β€” join back, leave front
Inventory Manager β€” add/remove/check
Unique Only β€” deduplicate a list
Start Lesson β†’
πŸ”„

4.3 Iterating Over Lists

4 challenges

Loop through lists with for item in list and enumerate(). Search, filter, and transform data.

for item inrange(len())enumerate()filtertransform
Challenges
Grade Calculator β€” average a list
Search & Count β€” count occurrences
High Scores β€” find max/min + positions
List Filter β€” build even-only list
Start Lesson β†’
πŸ—‚οΈ

4.4 Dictionaries: Key-Value Pairs

4 challenges

Store labeled data with dictionaries. Access, add, update entries and handle missing keys safely with get().

dict syntaxkey accessget()inKeyErrorupdate
Challenges
Contact Book — store name→phone
Word Counter β€” count word occurrences
Inventory System β€” track quantities
Emoji Translator — map words→emoji
Start Lesson β†’
πŸ”

4.5 Iterating Over Dictionaries

4 challenges

Loop through dicts with .keys(), .values(), .items(). Build dicts from data and work with nested structures.

.keys().values().items()nested datalist of dicts
Challenges
Student Report β€” formatted report card
Most Popular β€” find highest-value key
Roster Builder — team→players dict
Data Dashboard β€” per-student averages
Start Lesson β†’
πŸ—οΈ

Unit Project Contact Manager

capstone

Build a full contact manager app: store contacts as a list of dictionaries, support add/search/delete/list operations via a menu loop.

listsdictslist of dictsmenu loopCRUDsearch
What You'll Build
Add contacts (name, phone, email)
List all contacts formatted
Search by name
Delete contacts + menu loop
Start Project β†’

Ready for Collections?

Lesson 4.1 introduces lists β€” Python's most versatile data structure.

Begin Lesson 4.1 β†’
Prerequisite: Unit 3 (Loops)