Visual walkthrough — List methods — append, insert, remove, pop, sort, reverse, count, index
This is the picture-first companion to List methods — append, insert, remove, pop, sort, reverse, count, index. Read it slowly; each step has one figure that carries the idea.
Step 1 — A list is a row of numbered slots
WHAT. Before any method exists, we need the stage. A Python list is a row of boxes laid left to right. Each box has a small number under it — its index — starting at , not .
WHY start here. Every method we meet is described by which index things live at and which indices they move to. Without the index ruler, words like "shift right" mean nothing. (This is the same numbering built in Lists — creation and indexing.)
PICTURE. Look at the figure: four boxes holding 3, 1, 2, 5. Under them the gray ruler reads . The value inside a box (blue) and the index below it (gray) are two different things — that difference is the source of half of all list bugs.

- — how many boxes there are (here ).
- The largest legal index is (here ), not . Asking for index falls off the end →
IndexError(see Exceptions — ValueError and IndexError).
Step 2 — append: drop into the next free slot
WHAT. lst.append(x) places x in the first empty box just past the end.
WHY it is the "cheap" one. The end already has nothing to its right, so no existing box has to move. This is why we later say append is O(1) — the work does not grow with list size.
PICTURE. The orange 5 slots into position . Nothing blue slides. The ruler simply grows one number.

- — the old length; it is the index of the new item, because indices run , so slot was the empty one.
appendreturns ==None==: it changes the list, it does not hand you a value.
Step 3 — insert: pry the row open, then drop in
WHAT. lst.insert(i, x) puts x at index i. But i is already occupied — so everyone from i onward must slide one step right to make a gap.
WHY it is the "expensive" one. To open a hole near the front, many boxes move. That sliding is real work and grows with how much sits to the right — the O(n) cost.
PICTURE. Watch the arrows: every item at index (the 1, 2, 5) hops right by one, then orange 9 lands in the freed slot .

- — the target index where
xwill sit afterwards. - — the index of any item currently at or past
i; each such item gains . - Items with do not move — the arrows only start at the insertion point.
Step 4 — remove: search by value, then close the gap
WHAT. lst.remove(x) scans left to right, finds the first box whose value equals x, deletes it, then slides everyone after it one step left to close the hole.
WHY value, not index. This is the trap. remove is a searcher: you tell it what to throw away, not where. Calling [5,6,7].remove(0) looks for the value 0, finds none, and raises ValueError.
PICTURE. From [3, 9, 1, 2, 5] we remove(1). The red box is the value 1 at index . It vanishes; the 2 and 5 to its right slide left to fill the gap.

- — the value being matched (not an index).
- — the index where that value first appears; only the first match is removed.
- — every index past ; each item there moves down by one. Length becomes .
- Returns ==
None==.
Step 5 — pop: the same close-up, but it hands you the item
WHAT. lst.pop(i) removes the item at index i and returns it. With no argument, i = -1, meaning the last box.
WHY it is the twin of remove — with one crucial difference. The gap-closing motion is identical to Step 4. The difference is direction of communication: pop speaks by index and hands the item back; remove speaks by value and hands back nothing. "pop pays you back, remove robs silently."
PICTURE. Two panels. Left: pop() lifts the last box 5 out and the returned value flies to a variable. Right: pop(0) lifts the front box, then everyone slides left.

- by default — Python's shorthand for "last slot", so
pop()needs no shifting (nothing is to its right). - — the front; this does trigger a full left-slide (also O(n)).
- The returned value is the whole point of
pop; ignoring it wastes the method.
Step 6 — sort and reverse: reorder without adding or removing
WHAT. sort() rearranges the same items into ascending order. reverse() flips the current order end-for-end. Neither adds nor deletes — the multiset of values is untouched; only positions change.
WHY two separate methods. reverse is blind — it flips whatever order you have. It does not know about size. So "biggest first" is not reverse(); it is sort() then reverse(), or the one-shot sort(reverse=True).
PICTURE. Top row: [4,2,4,1] → sort() → [1,2,4,4] (arrows show each value gliding to its ranked slot). Bottom row: reverse() mirrors the row about its centre → [4,4,2,1].

sort()compares items with<; every element must be comparable to the others. Both mutate in place and return ==None== — for a new list use the functionsorted()instead (see sorted() vs list.sort()).
Step 7 — count and index: the questions that change nothing
WHAT. count(x) returns how many boxes hold value x. index(x) returns the slot number of the first box holding x.
WHY these read but never write. They are pure questions. The list is exactly the same before and after — no arrows, no sliding. (The very same reading idea works on text in Strings — index and count methods.)
PICTURE. On [4,4,2,1]: green tally marks over the two 4s give count(4)=2; a green pointer lands on slot for index(2)=2.

index(x)on a missing value raisesValueError— it promises a real slot number, so "not found" cannot be answered with a number.
Step 8 — The degenerate cases (never skip these)
WHAT. The empty list and the "nothing to move" ends.
WHY. A method must behave at the edges, or your program crashes on the day the list is empty.
PICTURE. Three tiny panels:
[].pop()— no last box exists →IndexError.[].append(9)— the only method that is always safe on an empty list; the ruler is born at .[5].index(5)→ but[5].index(9)→ValueError.

| Call on empty/edge | Result | Why |
|---|---|---|
[].append(x) |
[x] |
end is always free |
[].pop() |
IndexError |
no last slot |
[].remove(x) |
ValueError |
value can't be found |
[5].pop(0) |
returns 5, list [] |
closing an empty gap needs no slide |
The one-picture summary
Every method is one of four motions on the ruler of slots: grow (right end / pry open), shrink (close a gap), reorder (permute in place), or read (touch nothing). Mutating motions return None; only pop, count, index hand a value back.

Recall Feynman retelling — the whole walkthrough in plain words
Picture a shelf of numbered cubbyholes, counted 0, 1, 2, … append sets a box in the next empty hole at the far right — nobody has to budge, so it's quick. insert shoves a box into a chosen hole and everyone to its right scoots over one to make room — lots of scooting if it's near the front, so it's slow. remove walks the shelf looking for a box with a certain label, tosses the first match, and the boxes to its right scoot back to fill the hole — and it hands you nothing. pop also lifts a box out and closes the gap, but you name a hole number and it hands you the box. sort lines the same boxes up small-to-big; reverse just mirrors the row — reverse is dumb, it doesn't sort, so "big-first" means sort then flip. count and index only look: how many red boxes, and which hole is the first red box in — they never move anything. And at the edges: an empty shelf lets you append but pop on it screams, because there's no box to hand over.
Cross-check with the categories: mutating verbs return None because they hand back a shelf, not a box → see Mutability vs Immutability in Python, and why fixed-shelf tuples refuse these growing verbs entirely. Hinglish version: 1.2.22 List methods — append, insert, remove, pop, sort, reverse, count, index (Hinglish).
Flashcards
After [3,9,1,2,5].remove(1), what is the list and what is returned?
[3,9,2,5]; returns None (it deletes the first value 1 at index 2, then slides right side left).Why is append cheaper than a front insert?
[5,6,7].pop(0) — value and resulting list?
5; list becomes [6,7].Why does [5,6,7].remove(0) raise ValueError?
remove matches by value, and value 0 isn't present; it does not treat 0 as an index.On [4,4,2,1], what are count(4) and index(2)?
count(4)=2, index(2)=2.How do you get descending order, and why isn't reverse() enough?
sort(reverse=True) (or sort then reverse); reverse only flips current order, it never sorts.Which three list methods hand back a useful value?
pop (the removed item), count (a number), index (a slot number).