2.4.1 Lists

Lists

The Wildcats coach records a sequence of training scores. An array fixes the number of positions when it is created; a list keeps an ordered sequence whose number of items can change.

Explore the idea
Read the list from index zero
A snapshot of three scores
Index Score
0 2
1 0
2 3

The score 0 is still an item. This snapshot has three items, and its last index is 2.

Describe a changing sequence

Appending a score of 1 puts it after the existing three scores at index 3. Removing a middle item closes the gap: later items move one index toward zero.

Predict and check