Elena' s AI Blog

The Treasure Chest: Lists

05 Jan 2026 / 11 minutes to read

Elena Daehnhardt


Lesson 8 of 11 72%


TL;DR: A list is a collection of items. `friends = ['Sam', 'Alex']`. You can find items by their position: `friends[0]` is 'Sam'.

The Problem with Variables

Variables are great for storing one thing. name = "Sam"

But what if you want to invite 20 friends to a party? Use 20 variables?

friend1 = "Sam"
friend2 = "Alex"
friend3 = "Lee"
friend4 = "Kim"
# ... 16 more?! ๐Ÿ˜ซ

Thatโ€™s messy! There must be a better wayโ€ฆ

Enter the List (The Treasure Chest) ๐Ÿ“ฆ

Lists store multiple items like a treasure chest

A List is a variable that can hold many things. It uses square brackets [].

friends = ["Sam", "Alex", "Lee", "Kim"]

Now we have one box (friends) containing four names!

Visual representation:
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚        friends LIST             โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ "Sam"โ”‚"Alex"โ”‚ "Lee"โ”‚  "Kim"   โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚  [0] โ”‚  [1] โ”‚  [2] โ”‚   [3]    โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐ŸŽฎ Real-World Connection

This is how Spotify stores your playlists! Your โ€œFavoritesโ€ is a list of songs. Instagram has a list of your posts. Every game has a list of high scores. Lists are EVERYWHERE!

Finding Things in the Box (Indexing) ๐Ÿ”

List items are numbered starting from 0

How do we get โ€œSamโ€ out of the box? We use the position number (index).

Important Rule: Computers start counting at 0. ๐Ÿคฏ

โ€œSamโ€ โ€œAlexโ€ โ€œLeeโ€ โ€œKimโ€
0 1 2 3
print(friends[0])  # Prints "Sam"
print(friends[2])  # Prints "Lee"
print(friends[3])  # Prints "Kim"

๐Ÿš€ Try This NOW!

What will this print?

colors = ["red", "blue", "green", "yellow"]
print(colors[1])
Click to check! It prints "blue" because blue is at index 1! (Remember: we start counting from 0!)

Why Start at 0?

Itโ€™s a computer science tradition! Think of it like this:

  • Index 0 = โ€œzero steps from the startโ€
  • Index 1 = โ€œone step from the startโ€
  • Index 2 = โ€œtwo steps from the startโ€

Once you get used to it, it makes sense! ๐Ÿ˜Š

Making Changes ๐Ÿ”ง

Lists can change!

Adding Items

friends = ["Sam", "Alex"]
friends.append("Jo")
print(friends)  # ["Sam", "Alex", "Jo"]

Changing Items

Oh no, โ€œAlexโ€ canโ€™t come. โ€œMaxโ€ is coming instead.

friends = ["Sam", "Alex", "Lee"]
friends[1] = "Max"
print(friends)  # ["Sam", "Max", "Lee"]

Removing Items

friends = ["Sam", "Alex", "Lee"]
friends.remove("Alex")
print(friends)  # ["Sam", "Lee"]

Counting Items

How many friends do I have?

friends = ["Sam", "Alex", "Lee", "Kim"]
print(len(friends))  # 4

(len is short for โ€œlengthโ€)

Loops + Lists = Magic! โœจ

Remember loops? They are BEST FRIENDS with lists!

friends = ["Sam", "Alex", "Lee", "Kim"]

for friend in friends:
    print("Hello", friend + "!")

Output:

Hello Sam!
Hello Alex!
Hello Lee!
Hello Kim!

This is how Instagram shows you 100 photos. It just loops through a list!

Another Example: High Scores

scores = [100, 95, 87, 92, 88]

for score in scores:
    print("Score:", score)
    if score >= 90:
        print("  Grade: A!")
    else:
        print("  Grade: B")

List Tricks ๐ŸŽฉ

Get the First and Last

fruits = ["apple", "banana", "cherry", "date"]

first = fruits[0]      # "apple"
last = fruits[-1]      # "date" (negative counts from end!)

Slice a List (Get a Part)

fruits = ["apple", "banana", "cherry", "date", "elderberry"]

middle = fruits[1:4]  # Gets index 1, 2, 3 (not 4!)
print(middle)  # ["banana", "cherry", "date"]

Check if Something is in the List

fruits = ["apple", "banana", "cherry"]

if "banana" in fruits:
    print("Yes, we have bananas!")

Try It Yourself

Challenge 1: Make a list of your 3 favorite foods.

foods = ["pizza", "ice cream", "tacos"]

Challenge 2: Print the first one using index.

print(foods[0])  # pizza

Challenge 3: Add a 4th food to your list.

foods.append("cookies")
print(foods)  # ["pizza", "ice cream", "tacos", "cookies"]

Challenge 4: Use a loop to print all your foods!

for food in foods:
    print("I love", food)

Extra Challenge: The Todo List

Make a program that:

  1. Creates a list of 3 tasks
  2. Prints all tasks
  3. Asks which task is done (by index)
  4. Removes that task
  5. Shows remaining tasks

Solution:

tasks = ["Clean room", "Do homework", "Feed cat"]

print("Your tasks:")
for i in range(len(tasks)):
    print(i, "-", tasks[i])

done = int(input("Which task is done? (enter number): "))
finished = tasks[done]
tasks.remove(finished)

print("\nRemaining tasks:")
for task in tasks:
    print("-", task)

Common Mistakes & Fixes

โŒ Wrong: friends = ["Sam", "Alex"
Why it fails: Missing closing bracket!

โœ… Right: friends = ["Sam", "Alex"]
Always close your brackets!

โŒ Wrong: print(friends[5])
Why it fails: If list has 3 items, index 5 doesn't exist!

โœ… Right: print(friends[2])
Indexes go from 0 to (length - 1)

โŒ Wrong: friends.add("Jo")
Why it fails: The method is called .append(), not .add()

โœ… Right: friends.append("Jo")
Remember: append, not add!

โŒ Wrong: friends(0)
Why it fails: Use square brackets, not parentheses!

โœ… Right: friends[0]
Lists use [ ], functions use ( )

๐Ÿ” Bug Hunter Betty Says:

โ€œIf you see โ€˜IndexError: list index out of rangeโ€™, it means youโ€™re trying to access an item that doesnโ€™t exist! If your list has 3 items (indexes 0, 1, 2) and you try to access index 5, Python gets confused. Always check how long your list is with len()!โ€

๐ŸŽ‰ Achievement Unlocked: List Collector! Wizard Level: Enchanter (8/10 complete)

๐Ÿ“ Todayโ€™s Spell Book (Quick Reference)

# Create a list
my_list = ["apple", "banana", "cherry"]

# Access items (indexing starts at 0!)
first = my_list[0]     # "apple"
last = my_list[-1]     # "cherry" (from end)

# Modify list
my_list.append("date")     # Add to end
my_list.remove("banana")   # Remove specific item
my_list[0] = "apricot"     # Change item at index 0

# Get info about list
length = len(my_list)      # How many items?
if "apple" in my_list:     # Is "apple" in the list?
    print("Found it!")

# Loop through list
for item in my_list:
    print(item)

# Useful list methods:
# .append(item) - add to end
# .remove(item) - remove specific item
# .sort() - sort alphabetically/numerically
# .reverse() - reverse the order

๐Ÿ’ก Parent/Teacher Tip

The โ€œstarting at 0โ€ concept can be confusing! Try this: Line up 4 toys. Point to the first one and say โ€œThis is zero steps from the start.โ€ Point to the second and say โ€œThis is one step from the start.โ€ This physical demonstration often makes it click!

๐ŸŒŸ Fun Fact

Lists can hold ANY type of dataโ€”even other lists! You can have a list of lists (like a grid for tic-tac-toe), or a list that mixes numbers and text: weird_list = [42, "hello", True, 3.14]. Python is very flexible!

In the next lesson, weโ€™ll learn about Functionsโ€”how to create your own custom commands!


This post is part of the Python Basics for Kids series, based on โ€œPython for Kids from 8 to 88โ€.

desktop bg dark

About Elena

Elena, a PhD in Computer Science, simplifies AI concepts and helps you use machine learning.

Citation
Elena Daehnhardt. (2026) 'The Treasure Chest: Lists', daehnhardt.com, 05 January 2026. Available at: https://daehnhardt.com/courses/book0/08-lists/
Course Library