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).