All subjects · Computer Science · WCP01 Principles of Computer Science

Data structures: arrays, lists, dictionaries, records, tuples and sets

Edexcel IAL Computer Science · WCP01 Principles of Computer Science

A data structure organises related data so it can be used efficiently. You need to know the properties of six structures and hand-trace operations on them (spec point 4.2.1). Code examples use Python, as in the Pearson papers.

Practise this in the app: instant marking and a fix for every mistake. Free, no email needed to start.

Practise this lesson

Arrays and lists

Dictionaries, records, tuples and sets

Set operations

For A = [2, 4, 6, 8, 10] and B = [3, 6, 9] (written in order here, although sets are unordered):

OperationMeaningResult
Union A ∪ BItems in A or B or in each[2, 3, 4, 6, 8, 9, 10]
Intersection A ∩ BItems in A and also in B[6]
Difference A - BItems in A but not in B[2, 4, 8, 10]

Tracing a 2D array

grid = [[3, 8, 1], [6, 2, 9], [4, 7, 5]]

Always check whether the question indexes from 0, as Python does.

Worked example

Show the contents of the dictionary after these operations. cities = {'Berlin': 3.6, 'Lagos': 15.4} cities['Lima'] = 10.1 del cities['Berlin'] cities['Lagos'] = 16.0

  1. Start: {'Berlin': 3.6, 'Lagos': 15.4}
  2. Add Lima: {'Berlin': 3.6, 'Lagos': 15.4, 'Lima': 10.1}
  3. Delete Berlin: {'Lagos': 15.4, 'Lima': 10.1}
  4. Assigning to an existing key replaces its value: {'Lagos': 16.0, 'Lima': 10.1}

Answer: {'Lagos': 16.0, 'Lima': 10.1}

Key idea: Array: fixed size, one type, indexed. List: resizable. Dictionary: unique keys to values. Record: named fields of mixed types. Tuple: immutable. Set: unordered, unique; union, intersection, difference.

Check yourself

  1. grid = [[3, 8, 1], [6, 2, 9], [4, 7, 5]]. What is grid[1][2]?
    Show answer

    9. Row 1 is [6, 2, 9]; column 2 is 9.

  2. grid = [[3, 8, 1], [6, 2, 9], [4, 7, 5]]. What is the sum of row 2?
    Show answer

    16. 4 + 7 + 5 = 16.

  3. grid = [[3, 8, 1], [6, 2, 9], [4, 7, 5]]. What is the total of column 0?
    Show answer

    13. 3 + 6 + 4 = 13.

  4. A = {1, 3, 5, 7, 9} and B = {3, 4, 5, 6}. List the intersection of A and B in ascending order, separated by commas.
    Show answer

    3, 5. Items in A and also in B: 3, 5.

  5. A = {1, 3, 5, 7, 9} and B = {3, 4, 5, 6}. How many items are in the union of A and B?
    Show answer

    7. Union = [1, 3, 4, 5, 6, 7, 9], which has 7 items (duplicates count once).

  6. Which data structure cannot be changed after it is created?
    • Tuple
    • List
    • Dictionary
    • Set
    Show answer

    Tuple. Tuples are immutable.

  7. Which data structure is best for looking up a country's population from the country's name?
    • Tuple
    • One-dimensional array of integers
    • Dictionary
    • Set
    Show answer

    Dictionary. The name is a unique key mapped to its value.

  8. What is a record?
    • An unordered collection of unique values
    • A fixed-size collection of items of one type accessed by index
    • A collection that cannot contain duplicates
    • A single item made of named fields that can have different data types
    Show answer

    A single item made of named fields that can have different data types. For example name (text), age (integer), enrolled (Boolean).

Practise with instant feedback

Sources

Last updated 8 November 2026. Spotted a mistake? Tell us.