Unit content
Collections and basic data structures
Programs often need to work with groups of values rather than one value at a time. Collections organize several values according to rules that make particular operations convenient.
Sequences
A list or array stores values in an order. Elements can be visited one after another and are commonly accessed by position.
temperatures = [18, 21, 19, 23]
A sequence is appropriate when order and repeated values matter.
Maps
A map or dictionary associates keys with values:
population["Bilbao"] = 346000
The important operation is lookup by key rather than by numerical position.
Sets
A set stores distinct values and supports questions such as whether an element is present, or which elements belong to the union or intersection of two collections.
Choosing a structure
Different structures make different operations natural or efficient. A sequence is useful for ordered iteration, a map for keyed lookup and a set for membership and uniqueness.
Mutation
Some collections can be changed after creation by adding, removing or replacing elements; others are immutable. Mutation changes program state, so references to the same mutable collection can observe one another's changes.
A data structure is therefore not just a container: it organizes data around the operations the program needs to perform.