Skip to content

List Index Explorer

Run the List Index Explorer MicroSim Fullscreen
Edit in the p5.js Editor

About This MicroSim

Students read that lists "change in place" but never see the boxes shift. Here every operation is one click: append() grows the end, insert(1, ...) squeezes in and slides everything rightward, pop() shrinks the tail — and both the positive and negative index rows renumber before their eyes, with the exact Python line shown for each change. The String Test panel shows the real TypeError a string raises for the same in-place change, making the mutable/immutable divide concrete.

Learning objective: The student will be able to select items by positive and negative index and demonstrate how append, insert, and pop reshape a list in place.

  • Bloom's Taxonomy (2001): Apply → Analyze — use, demonstrate, differentiate
  • Interaction pattern: button-driven operations with one visible state change per click

How to Use

  1. Predict: after insert(1, ...), what index will "gold" have? Click and check.
  2. Watch the negative index row: which item always has index −1?
  3. Fill the list with append(), then pop() back down — the list reprints below the boxes after every change.
  4. Click String Test to see why word[0] = "X" fails on a string.

Iframe Embed Code

You can add this MicroSim to any web page by adding this to your HTML:

1
2
3
4
<iframe src="https://dmccreary.github.io/learning-python/sims/list-index-explorer/main.html"
        height="482px"
        width="100%"
        scrolling="no"></iframe>

Lesson Plan

Grade Level

Upper elementary and middle school (ages 10-14), Chapters 15-16 (Lists)

Duration

10 minutes

Prerequisites

  • String indexing (Chapters 8 and 14)

Activities

  1. Shift hunt (4 min): Students click insert and record which items got new indices and which kept theirs. Then the same for pop.
  2. Negative anchor (3 min): "No matter what you do, what is at index −1?" Students test with several operations.
  3. Mutable vs immutable (3 min): Compare the String Test error with the list behavior; students write one sentence for each.

Assessment

  • Student predicts the full index renumbering after an insert
  • Student can state which end pop() removes from
  • Student can explain the TypeError in the String Test panel

References

  1. Python Tutorial — More on Lists — official list methods documentation
  2. p5.js — the JavaScript library used to build this MicroSim