Lists - Organizing Related Data
Card 11 of 15

What Is a List?

"A list is an ordered collection of items. Instead of having separate variables for related data, group them together."

The Problem Lists Solve

# Without lists - messy and unscalable
fruit1 = "apple"
fruit2 = "banana"
fruit3 = "orange"
fruit4 = "grape"
# What if we have 100 fruits?

# With lists - organized and scalable
fruits = ["apple", "banana", "orange", "grape"]

List Structure: Position Matters

fruits = ["apple", "banana", "orange"]
"apple"
Index: 0
"banana"
Index: 1
"orange"
Index: 2
Important: Lists start at index 0, not 1!
Last index is always: len(list) - 1
Critical Concept: Lists are ordered - position matters. Each item has an index (position number) starting at 0.

Interactive List Explorer

Common List Operations

# Creating a list
fruits = ["apple", "banana"]

# Accessing items
first = fruits[0]        # "apple"
last = fruits[1]         # "banana"

# Adding items
fruits.append("orange")  # Add to end
fruits.insert(1, "grape") # Insert at position 1

# Removing items
fruits.remove("apple")   # Remove by value
item = fruits.pop()      # Remove and return last

# Getting length
count = len(fruits)      # How many items?

# Checking membership
has_apple = "apple" in fruits  # True or False

Looping Through Lists

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

# Method 1: Direct iteration
for fruit in fruits:
    print(fruit)

# Method 2: Using index
for ii in range(len(fruits)):
    print(ii, fruits[ii])
Mental Model: A list is like a row of numbered boxes. Each box holds one item. You can access any box by its number (index), but remember: the first box is #0, not #1.
"Lists let you group related data together and process them systematically. They're fundamental to working with multiple pieces of information."
[######################........] 11/15
> [WHY_IT_MATTERS]:
A variable holds a thought. A list holds a culture. Organizing data is organizing the mind.
Cute Computer Mascot