Use INSERT, APPEND, REMOVE, LENGTH on lists in AP pseudocode
Trace FOR EACH loops processing list elements
Predict list contents after a sequence of operations
Identify list out-of-bounds and index-shift errors
📈
Exam Impact: Topic 3.10 expands on 3.2. List operations are heavily tested in BI3 MCQ and required in the Create Task.
💡 Why This Matters
Spotify's queue is a list. Every add, remove, or reorder is a list operation. Building those features requires exactly the INSERT, APPEND, and REMOVE operations on this page.
AP Pseudocode List Operations
The AP exam uses specific procedure names. Memorize these exactly as they appear on the reference sheet.
songs = ["A","B","C"]
songs.append("D")
songs.insert(1,"X")
songs.remove("B")
n = len(songs)
third = songs[2]
songs <- ["A","B","C"]
APPEND(songs,"D")
INSERT(songs,2,"X")
REMOVE(songs,3)
n <- LENGTH(songs)
third <- songs[3]
FOR EACH and Index Shift After REMOVE
FOR EACH processes every element without managing an index. After REMOVE(list, i), every element after position i shifts left by one -- a second REMOVE at the same index now targets a different element.
Exam tip: Assigning to the loop variable in a FOR EACH does NOT modify the original list. Use indexed access to modify elements.
Practice Problems
🔎 Practice MCQ
Starting with lst = [10,20,30], after INSERT(lst,2,99), what is lst[3] (AP 1-indexed)?
⚠️ Predict your answer BEFORE clicking.
🔎 Practice MCQ
After these operations, what is LENGTH(nums)? nums <- [1,2,3,4,5] REMOVE(nums,3) APPEND(nums,10) APPEND(nums,11)
⚠️ Predict your answer BEFORE clicking.
🔎 Practice MCQ
Which statement about FOR EACH is NOT correct?
⚠️ Predict your answer BEFORE clicking.
🎮 Game
List Operation Tracer
Trace the list after each operation. 8 questions.
0
Correct
1/8
Question
0
Streak 🔥
🐛 Trace this code:
0/8
correct
💻 Python Code Editor
Practice Problems
Write Python and check your answer. Paste into Replit for complex programs.
Problem 1 of 3
Start with items=[1,2,3]. Append 4, print the length. Expected: 4
Hint: items.append(4) then print(len(items))
Problem 2 of 3
Print the sum of [5,10,15,20] using a loop. Expected: 50
Hint: total = total + n inside the loop.
Problem 3 of 3
Spot the error: should print last element of [4,8,12]=12 but crashes. print(lst[3])
Hint: Python is 0-indexed. Last element of 3-item list is index 2. Use lst[2] or lst[-1].
Frequently Asked Questions
APPEND always adds to the end. INSERT(lst,i,val) adds at position i, shifting everything at or after i right.
Yes. After REMOVE(lst,i), every element after position i shifts one position left. If you remove during a loop, you can accidentally skip elements.
AP: LENGTH(lst). Python: len(lst). Both count from 1 (a 3-element list has LENGTH 3). Indexing differences remain: AP is 1-based, Python is 0-based.
Whether you're a student, parent, or teacher — I'd love to hear from you.
Just want free AP CS resources?
Enter your email below and check the subscribe box — no message needed.
Students get daily practice questions and study tips. Teachers get curriculum resources and teaching strategies.
Typically responds within 24 hours
✓
Message Sent!
Thanks for reaching out. I'll get back to you within 24 hours.