StudyVault
Home Unit Overview Exam Technique Revision Techniques ← Previous Lesson Next Lesson →

← Back to Dashboard

Overlay:
0:00 / 0:00 Narration generated using AI text-to-speech.

Lists, Arrays, Records and 2D Structures

Why We Need Structured Data

Storing one value at a time in separate variables works fine for a handful of items, but quickly becomes unmanageable. A school might need to store scores for 30 students — using 30 separate variables such as score1, score2... score30 is impractical and makes looping impossible. Structured data types group multiple values together under a single name so they can be processed efficiently.

One-Dimensional Arrays — Python Lists

In Python, a list is the standard implementation of a one-dimensional array. Items are written inside square brackets, separated by commas, and accessed by their index (position), which starts at 0.

scores = [72, 85, 91, 64, 78]
print(scores[0])    # 72 (first element)
print(scores[2])    # 91 (third element)
print(scores[len(scores) - 1])   # 78 (last element)
Key Fact

Python list indices start at 0. A list with 5 elements has valid indices 0, 1, 2, 3, 4. Index 5 causes an IndexError. The last element can always be accessed as list[len(list) - 1]. The PLS does not include negative indexes, so list[-1] should not be used.

Iterating Over a List

The most natural way to process every item in a list is with a for loop. You can iterate over the items directly, or use range(len(list)) if you need the index:

# Direct iteration (when you don't need the index)
for score in scores:
    print(score)

# Index-based iteration (when you need to modify items)
for i in range(len(scores)):
    scores[i] = scores[i] + 5    # Add 5 bonus marks to each

Appending to a List

Python lists are dynamic — you can add new items using the append method (.append()). This adds the item to the end of the list:

names = []
for i in range(3):
    name = input("Enter name: ")
    names.append(name)
print(names)

Starting with an empty list [] and building it up with .append() inside a loop is a common pattern for collecting user input or building results dynamically.

Two-Dimensional Arrays — Nested Lists

A two-dimensional array is implemented in Python as a list of lists — also called a nested list. Think of it as a grid: the outer index selects the row, the inner index selects the column.

# A 3x3 grid of temperatures (rows = days, columns = times of day)
temps = [
    [12, 15, 14],
    [10, 18, 16],
    [9,  20, 17]
]
print(temps[0][1])   # 15 (row 0, column 1 = Monday noon)
print(temps[2][2])   # 17 (row 2, column 2 = Wednesday evening)

To visit every cell in a 2D list, use nested for loops — one for rows, one for columns:

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

for row in grid:
    line = ""
    for value in row:
        line = line + str(value) + " "
    print(line)

Output:

1 2 3
4 5 6
7 8 9

The outer loop gives each row as a list; the inner loop processes each value within that row. This nested-loop pattern is one of the most frequently tested 2D-array skills in the exam.

Records — Lists as a Table of Fields

A record groups related fields under a single name. In the PLS, a record is implemented as a list: each field is stored at a fixed position (index) rather than under a name, so the field order must be documented — usually with a comment.

# A student record as a list
# Field order: [name, age, score, passed]
student = ["Priya Sharma", 16, 88.5, True]

print(student[0])    # Priya Sharma
print(student[2])    # 88.5
Key Fact

A record is a list of fields in a fixed order, accessed by index rather than by name. Fields of different types can coexist in the same list — just like a real record might hold a name (string), age (integer), price (real), and available (Boolean) in one structure. Because there are no field names, always document the field order with a comment.

A common pattern is a list of records — a list of lists, where every inner list has the same number of fields in the same order. Think of it as a simple table:

# Field order for each record: [name, score]
students = [
    ["Ali", 72],
    ["Beth", 91],
    ["Carlos", 65]
]

for student in students:
    if student[1] >= 70:
        print(student[0], "has passed")

Output: Ali has passed / Beth has passed. Carlos (65) does not meet the threshold. This combines a list of lists (records), and a for loop with a conditional — exactly the kind of code that appears in exam “Amend” and “Write” questions. The PLS does not support ragged data structures, so every record in the table must have the same number of fields.

Practice Questions

Test yourself on this lesson. Pick a question, write your answer, then get it marked.

AI feedback
AI feedback is guidance, not a final exam mark. If you disagree, your teacher's view is always the tie-breaker.
← Back to unit
Video

© 2026 StudyVault · About · FAQ · Copyright & IP · Privacy · Disclaimers

StudyVault Education Ltd · registered in England and Wales, company no. 17490559 · 71–75 Shelton Street, London WC2H 9JQ