Fields, Records and Files
intermediate25 minLearning objectives
- Distinguish between fields, records and files
- Explain how related data is organised
- Model records using Python dictionaries
- Relate data organisation to real-world information systems
Learn
AQA 4.2.3 — Fields, records and files
Retrieval: the previous lesson's scores = [82, 67, 91, 74, 88] array stores five numbers, but not which student each belongs to, and not any other information about them. This lesson organises data properly around that gap.
- A field is a single piece of data about one thing (a name, a score, a student ID).
- A record is a group of related fields describing one specific entity — one student, one book, one order.
- A file is a collection of records of the same kind.
Python dictionaries model a record naturally — each key is a field name, each value is that field's data:
student = {"id": "S001", "name": "Aisha", "score": 82} # one record, three fields
A list of these dictionaries models a file:
students = [
{"id": "S001", "name": "Aisha", "score": 82},
{"id": "S002", "name": "Tom", "score": 67},
{"id": "S003", "name": "Priya", "score": 91},
]
Common mistake
Confusing a record with a file — a record is one entity's data; a file is the whole collection. Also easy to overlook: a well-designed record needs a field that uniquely identifies it (like "id" above) — without one, there's no reliable way to find or update exactly one record if, say, two students happened to share the same name.
Worked example — searching a file of records
def find_student(students, student_id):
for record in students:
if record["id"] == student_id:
return record
return None
result = find_student(students, "S002")
print(result["name"]) # "Tom"
Notice this is exactly the linear search algorithm from Sequence 5, just applied to records instead of plain values — searching a file for a matching record is one of the most common real uses of that algorithm.
Trace it
For students above, trace find_student(students, "S003"): which records does the loop check, in what order, and what does it return?
(It checks S001 - no match, then S002 - no match, then S003 - match, and returns the whole {"id": "S003", "name": "Priya", "score": 91} record.)
Real-world application
Every database-backed system you use — a school's attendance system, a library catalogue, an online shop's product list — is built from exactly this pattern: records with a unique identifying field, grouped into files (or database tables). Understanding fields/records/files is what makes it possible to design such a system, not just use one.
Challenge
Design a record structure (as a Python dictionary) for a library book loan system — decide which fields it needs, including a suitable unique identifier, and justify each field's inclusion in a sentence. Then write a small list of 3 sample records using your structure.
Looking ahead: the Dictionaries lesson later in this sequence goes deeper into the key-value operations (lookup, insertion, deletion) that records like these depend on.