Bootcamp Curriculum • 5 Modules • 12 Chapters • Multi-Language Runner (Python, JS, Java, C++) • Interactive Memory Trace • AI Mentor
CHAPTER 06 · LOOPS6 min read

Lists, arrays & nested collections

Instead of creating individual variables for every single item (`item1`, `item2`, `item3`), a List bundles ordered elements into a single data structure that can grow and shrink dynamically.

By the end of this chapter, you can:
  • Create, index, and modify lists.
  • Add and remove items with .append() and .pop().
  • Work with nested 2D lists representing a game matrix.
Explanation DepthTailor the level of detail to your learning goal
💻 Standard College Notes

List methods, indexing, appending, and slicing.

Key methods: .append(x), .insert(i, x), .pop(), .remove(x), and len(). Negative indexing allows easy access to the end with list[-1].

💡Lists are mutable: changing an element in place does not alter the list's memory address.

List operations: Indexing, Appending, Popping

Lists use square brackets `[]`. Elements can be accessed by index, modified in place, or appended to the end.

example_1.py
Ctrl + ↵ to run
Terminal Output
Ready to execute
Click "▶ Run Code" or press Ctrl+Enter to compile & run this snippet.

2D Lists: Treasure Map Matrix

Lists can contain other lists! A 2D list creates rows and columns, just like a game board or our Code Arena grid.

example_2.py
Ctrl + ↵ to run
Terminal Output
Ready to execute
Click "▶ Run Code" or press Ctrl+Enter to compile & run this snippet.
✦ Interactive Dry-Run Visualizer

Memory Trace: 2D Matrix Grid Indexing

Observe how nested arrays update specific row and column coordinates in memory.

STEP1 / 4
1grid = [["-", "-"], ["-", "-"]]👉 Executing
2grid[0][1] = "X"
3print(grid[0])
4print(grid[1])
VariableValue in MemoryData Type
grid[0]["-", "-"]auto
grid[1]["-", "-"]auto
Initialize 2x2 matrix in RAM

Two rows created. grid[0] is Row 0, grid[1] is Row 1.

Console Stream (stdout)
(No output generated yet)
Line 1: grid = [["-", "-"], ["-", "-"]]

🔧 List Shallow Reference Bug

A student tried to copy a list with b = a, but modifying b mutated a because both pointed to the same memory.

⚡ +100 XP
fix_bug.pyPython 3.10
⚡ Quick Revision Quiz

Predict The Output (2 Questions)

Question 1 of 2:
What is the result of [1, 2].append([3, 4]) followed by len()?
Question 2 of 2:
How do you access the last element of list `data`?

Your lightbulb moment

✧

The key takeaway
Lists store ordered sequences that can grow dynamically. Nested lists allow building 2D grids for games and tables.

Make it yours

Try adding a fourth item using .append() and access it with negative indexing fruits[-1].

Try editing the code in the playground above in Python, JavaScript, Java, or C++, and use the step-by-step Dry-Run Table to inspect how variables mutate in memory. If you get stuck, click the 🤖 AI Doubt Solver button on your screen for instant explanations!