Python 3.12 ·
✓ verified by execution on 2026-07-22
Lists in Python are dynamic, meaning they can grow, shrink, and be rearranged. Let’s explore the powerful built-in methods that let you manipulate lists.
Adding Items
You can add items to a list using append() or insert().
append() places the new item at the very end. insert() lets you choose the exact position.
Unlike string methods (which return brand new strings), list methods like sort() modify the original list in place. Because they alter the existing object, they don’t need to return a new list. In fact, they return None.
Predict what happens if you try to assign the result of sort() to a variable!
If you ever see None when you expected a list, you probably assigned the result of an in-place method!
Check yourself
Does the sort() method return a new sorted list?
Reveal answer
No, sort() modifies the list in place and returns None. — List methods like sort() modify the list in place and evaluate to None.
If a list has multiple identical items, what does remove() delete?
Reveal answer
Only the very first occurrence of the specified value. — remove() scans from the beginning and stops after deleting the first match.
What happens if you call pop() without providing an index?
Reveal answer
It removes and returns the very last item in the list. — By default, pop() targets the last item (index -1).
Challenges
Challenge 1 +15 XP
You are managing a line at a store. Add 'Charlie' to the end of the line, then serve the first person by removing them from the front of the line (index 0). Print the final line.
python
Test 1 — expects "['Bob', 'Charlie']\n"
Need a hint? (−25% XP)
Use append('Charlie') to add to the end, and pop(0) to remove the first person.
Show solution (0 XP)
line = ['Alice', 'Bob']line.append('Charlie')line.pop(0)print(line)
Challenge 2 +20 XP
Sort the list of high scores from lowest to highest, then remove the lowest score. Print the resulting list.
python
Test 1 — expects "[82, 88, 95, 100]\n"
Need a hint? (−25% XP)
First call sort() on the list. Since it sorts lowest-to-highest by default, the lowest score will be at index 0. Then call pop(0).
Array or Linked List? Score the Workload, Not the Table — Everyone memorises the table - arrays index fast, linked lists insert fast - and still cannot pick one. Run both structures against the same operations here and watch the totals swap places depending only on what the code actually does.
Stacks and Queues, Shown Doing the Jobs They Exist For — Knowing that a stack is last-in-first-out explains nothing about why anyone wanted one. Here a stack matches brackets and catches the error a counter would miss, and a queue runs a ring buffer whose values never move at all.
A Heap Is a Tree You Can Store in a Flat Array — Heaps are taught as trees and implemented as arrays, and the join between the two is usually three index formulas nobody explains. Watch a value sift up and down here, moving in the tree and the array at the same time, one swap per click.
100% Accurate and Useless: Pick a Model Before You See Its Score — Nobody overfits on purpose. They overfit because the number in front of them is going up. Tune a classifier on training data here, commit to it, and only then find out what it scores on data it has never seen.
No Sorting Algorithm Wins. Look at Your Data First. — Insertion sort is not slow and quicksort is not fast - each is the cheapest choice for some shape of input and the dearest for another. Predict the winner across five shapes here and watch a single favourite fail.
Pick the Structure: Ten Requirements, and Nobody Tells You the Answer — Every other page here takes one structure apart. This one starts where real work starts - with a requirement that never names the structure. Ten jobs, four candidates each, and the wrong answers are the ones people reach for by habit.
How Embeddings Work, Counted by Hand — An embedding turns a word into numbers so that similar words land near each other. Build real word vectors from your own text, see why cat and dog score alike without ever appearing together, and why similarity is measured by angle rather than distance.