0%

Dictionaries and Other Collections · capstone

Capstone project: Project: Build a Searchable Mini Catalog

You now have the pieces for a small structured information system:

  • for records with labeled fields;

  • a for several records in order;

  • for processing every record;

  • for focused operations;

  • a search function that returns a dictionary or None;

  • input for a real query.

Your project combines them into a searchable mini catalog.

The catalog records

The starter contains three books. Keep their data and shape:

catalog = [
    {
        "title": "Kindred",
        "creator": "Octavia E. Butler",
        "year": 1979,
    },
    {
        "title": "A Wizard of Earthsea",
        "creator": "Ursula K. Le Guin",
        "year": 1968,
    },
    {
        "title": "Python Crash Course",
        "creator": "Eric Matthes",
        "year": 2023,
    },
]

Every record has the same required keys. You may add more records after the project passes, but keep these three so the prepared search can be graded.

format_item(item)

Return one line in this exact form:

Kindred by Octavia E. Butler (1979)

The function receives one dictionary and returns a . It does not print.

show_catalog(catalog)

Print the heading:

CATALOG

Then print every record as a numbered line starting at 1:

1. Kindred by Octavia E. Butler (1979)

Call format_item(item) for the text after the number, and keep a counter beside the loop for the number itself, the way you have since Chapter 7.

find_by_title(catalog, query)

Use the contract from “Search a List of Records”:

  1. clean the query with .strip().lower();

  2. loop through the records;

  3. compare with each lowercase title;

  4. return the matching dictionary;

  5. return None after the loop if no title matches.

The top-level program

After the function definitions and catalog:

  1. call show_catalog(catalog);

  2. ask exactly Search by title: ;

  3. call find_by_title;

  4. print No matching title. if the result is None;

  5. otherwise print Found: followed by format_item(match).

Submit supplies this query:

  PYTHON CRASH COURSE

Your cleaning should make it find the third record without changing the stored title.

Build in three passes

1. Format one record

Complete format_item. Call it temporarily with catalog[0] and verify the line.

2. Show all records

Complete show_catalog. Check the numbering, record order, and exact punctuation.

3. Search

Complete find_by_title, then connect the input and result branch. Try an existing title with strange capitalization, then a missing title.

Read the final structure

The top-level program should be short. It says to show, ask, search, and report. The functions hold the details, the list holds the order, and each dictionary gives one record meaningful fields.

That is the central outcome of this chapter: choosing structures that make the information and the operations agree.

Chapter 10 turns to the failures that real input and imperfect data can cause. You will learn to read , validate before converting, and handle specific expected errors without hiding unexpected ones.

Task

Build the searchable mini catalog described in the lesson.

Requirements:

  1. Complete format_item(item) so it returns title by creator (year) from one .

  2. Complete show_catalog(catalog). Print CATALOG, then every record as a numbered line starting at 1. Call format_item for each record.

  3. Complete find_by_title(catalog, query). Clean the query, return the matching dictionary, or return None after the .

  4. Keep the three starter records and their exact fields.

  5. After the definitions and data, show the catalog.

  6. Ask exactly Search by title: .

  7. Print No matching title. for None, or Found: followed by the formatted matching record.

Submit uses prepared input, so you do not need to type during grading.