Published lesson · 30 minutes
Organise data in lists and dictionaries
Objective: Represent several records as dictionaries in a list and retrieve fields with clear names.
Understand the idea
Organise data in lists and dictionaries works best when the learner can explain the reason behind each step, not just copy a result. A list preserves order; a dictionary associates a key with a value. Together they can model a small collection of records without a database.
A community garden keeps sample plot names and water needs in a list of dictionaries for a simple printed summary. Treat the names and details as invented practice information; the example is for learning a method and does not describe a live service.
A dependable sequence is: Choose consistent keys, loop through records and use `.get` when a value may be missing. Write down the important decision before you begin so another person can follow the reasoning.
Test an empty list and a record without an optional field. Do not assume user-entered text is valid or complete. Compare the result with the objective, then change one thing at a time if the first attempt does not work.
Add a sample plot and trace which dictionary fields the summary reads. Explain one assumption that would need checking before anyone used a similar result outside the classroom.
Keep a short record of the choices you made and the evidence you used to check them. A useful practice result is understandable by another learner, stays within the stated scope and makes its limitations visible before anyone relies on it.
Worked examples
Organise data in lists and dictionaries: practice example
Explore how organise data in lists and dictionaries supports the lesson objective with a small synthetic example.
main.py
plots = [{"name": "North bed", "litres": 4}, {"name": "Herb corner", "litres": 2}]
for plot in plots:
print("{}: {} litres".format(plot["name"], plot["litres"]))Practice tasks
Explore organise data in lists and dictionaries
Use the worked example for “Organise data in lists and dictionaries”. Change one small detail to suit a different synthetic community situation, then explain what you expected and how you checked whether the change still met the lesson objective.
Build a Python practice example
Create a small practice result that demonstrates this objective: Represent several records as dictionaries in a list and retrieve fields with clear names. Use only synthetic information, keep the first version focused, and write down one limitation that a later version should address.
Review and explain the result
Review your “Organise data in lists and dictionaries” result as if another learner will use it without your explanation. Identify one strength, one exact point that may be unclear, and a revision that would make the result easier to understand or use.
Organise data in lists and dictionaries becomes easier when you choose consistent keys, check the result and explain the choice to another learner.
Course overview