Practice Flashcards
Flip to reveal answersHow are items in a list addressed?
Track your progress — Sign up free to save your progress and get smart review reminders based on spaced repetition.
All 5 Flashcards — Arrays and lists
Sign up free to track progress and get spaced-repetition review schedules.
Question
How are items in a list addressed?
Answer
By position, starting at 0. A list of four items has positions 0, 1, 2 and 3, so asking for position 4 is an error — the commonest list bug there is.
Question
How do you add to and remove from a dynamic list?
Answer
append adds at the end, insert(position, value) adds anywhere and shifts the rest along. remove(value) takes out the first match, and pop() removes the last item and gives it back.
Question
Why must you not remove items while looping over a list?
Answer
Removing shifts everything after it down one place while the loop counter moves up, so items get skipped silently. Build a new list instead, or loop over a copy.
Question
What is a 2D list and how is it addressed?
Answer
A list whose items are themselves lists — a grid. It is addressed [row][column], always in that order: grid[1][2] is row 1, column 2.
Question
Why does visiting every cell of a grid need a nested loop?
Answer
The outer loop gives you each row, which is itself a list; the inner loop reaches the individual values inside it. That is also why scanning a grid is O(rows × columns).
Read the notes
Full study notes for Arrays and lists
Topic 6.2 hub
Data structures
More from Topic 6.2
All flashcards in this topic
Computer Science exam skills
Paper structures & tips
Track your progress with spaced repetition
Sign up free — Aimnova tells you exactly which cards to review and when, so you remember everything before your IB exam.
Start Free