Organizing Data

Recap and Feedback


In this part, you used dictionaries to name information, lists to collect records, and nested structures to represent relationships. You also reused familiar loops to build grouped summaries and learned to distinguish a new outer structure from independent contents.

The important question is no longer only whether a result contains the expected values:

Does the representation preserve the information we need, and does it share only the objects we intend to share?

Equipment Catalogue

The concluding exercise returns to equipment records with identifiers, names, categories, and availability. It brings the part’s central representation decisions together: preserving individual items, deriving summaries, and choosing what returned data should share.

Equipment catalogue

0 / 35 points

Implement three functions for valid equipment records containing exactly id, name, category strings and an available Boolean. Identifiers are unique and case-sensitive; names may repeat. None of these three functions prints or changes the input.

  1. available_items(items) returns a new list of copied flat records for available equipment, preserving order. The returned records must be independent of the originals.
  2. category_counts(items) returns a dictionary mapping each occurring category to a new {"total": ..., "available": ...} record. Count physical items, including repeated names. Each category needs an independent summary.
  3. catalogue_lines(items) uses category_counts and returns lines ordered by category using Python’s default string order. Each line has exactly the format category: available/total available.

For two media items with one available and one available outdoors item, the lines are ["media: 1/2 available", "outdoors: 1/1 available"]. Empty input produces [], {}, and [] respectively. Choose any smaller helpers you find useful. Test both the values and the effects of changing a returned record.

The starter also supplies sample data and show_catalogue(items), a small terminal dashboard that calls your functions. Do not put printing into the three data functions. Run main.py to see their current results together; the dashboard itself is supplied display code and is not one of the functions you need to implement.

After completing the catalogue, shift from producing the expected values to asking which tests reveal mistakes that ordinary examples might conceal.

Make the Design Reasoning Explicit

An implementation demonstrates behavior for the cases that run. A separate explanation connects its choices about keys and copies to the information the catalogue must preserve.

Explain catalogue choices

0 / 10 points

A borrowing catalogue stores one record per physical item. Identifiers are unique; names may repeat. A category summary counts all items in each category. For example:

items = [
{"id": "E10", "name": "Camera", "category": "media", "available": True},
{"id": "E11", "name": "Camera", "category": "media", "available": True},
]
def available_items(items):
result = []
for item in items:
if item["available"]:
result.append(item.copy())
return result

Callers must be able to edit a selected record without changing the original catalogue. Explain why identifiers and category names serve different purposes, using the two same-named items above. Then explain how available_items meets the independence requirement and give a concrete mutation test with its expected result. Keep the explanation tied to these records and requirements.

Check Your Understanding

  1. What determines whether a key, a position, or an entire record is the useful unit?
  2. What can a shallow copy leave shared?
  3. How does a grouped total reuse the accumulation pattern from Part 2?
  4. What information disappears when original records are replaced by a summary?

Feedback

Finish the part with the short reflection and feedback form below.

Reflection and feedback

0 / 5 points

Consider the following statements and answer them based on your experiences from studying the materials and working on the assignments in this part. When answering the numeric statements, answer them so that value 1 means that you strongly disagree with the statement, and value 7 means that you strongly agree with the statement. Please be as honest as possible when answering. The feedback will be used to improve the course.

Looking Ahead

The catalogue disappears when the program stops unless we store it somewhere. Part 5 introduces files, CSV, and JSON, together with the checks needed when data comes from outside our own code.