The flight director stops by and asks Rocket which entries mention the clock. Rocket picks 2 and starts scrolling with his finger on the screen, counting out loud.
Halfway down, he laughs at himself. "I built a tool so I would not have to do this," he says.
Raven nods toward the stub list in main. "What do you notice?" she asks. "Search is next on the plan. And we already wrote one, for the text log in week 8."
Nova shows the old search and the new data side by side. "Would you like a hint?" she asks. "Return the matching entries as a list, without printing. Then printing them is a separate job."
Rocket writes search_entries so it gives back a list.
search_entries checks each entry. It matches when the word appears in the text, ignoring capitals, or in the tag. It returns a new list and prints nothing, which makes it easy to test next week.
Type it below format_entry.
def search_entries(entries, word):
"""Entries whose text or tag contains word, ignoring capitals."""
word = word.lower()
found = []
for entry in entries:
if word in entry["text"].lower() or word in entry["tag"]:
found.append(entry)
return found run_search asks for the word, calls search_entries, and prints each match with format_entry. Type it below show_entries.
def run_search(entries):
"""Ask for a word and print the matching entries."""
word = input("Search for: ").strip()
found = search_entries(entries, word)
for number, entry in enumerate(found, start=1):
print(format_entry(number, entry))
print(f"Matches found: {len(found)}") In main, add the choice 3 branch below choice 2, and change the stub list to just ["4"]:
elif choice == "3":
run_search(entries) With the same three saved entries as yesterday, three searches look like this:
Mission Log ready. Entries loaded: 3 1 Add 2 List 3 Search 4 Stats 5 Quit Choose 1 to 5: 3 Search for: CLOCK 1. 2026-04-10 [build] Built the launch clock 2. 2026-04-10 [test] Tested the clock with 65 seconds 3. 2026-04-11 [idea] Add a sound when the clock ends Matches found: 3 1 Add 2 List 3 Search 4 Stats 5 Quit Choose 1 to 5: 3 Search for: idea 1. 2026-04-11 [idea] Add a sound when the clock ends Matches found: 1 1 Add 2 List 3 Search 4 Stats 5 Quit Choose 1 to 5: 3 Search for: rocket Matches found: 0 1 Add 2 List 3 Search 4 Stats 5 Quit Choose 1 to 5: 5 Log saved. See you next mission!
| Search word | Matches "Built the launch clock" (tag build)? |
|---|---|
| CLOCK | ? |
| launch | ? |
| bui | ? |
| rocket | ? |
| test | ? |
search_entries returns a list, so a short file can check what it finds for different words.
# search_check.py: tries search_entries by itself
def search_entries(entries, word):
"""Entries whose text or tag contains word, ignoring capitals."""
word = word.lower()
found = []
for entry in entries:
if word in entry["text"].lower() or word in entry["tag"]:
found.append(entry)
return found
log = [
{"date": "2026-04-10", "tag": "build", "text": "Built the launch clock"},
{"date": "2026-04-11", "tag": "idea", "text": "Add a sound"},
]
print(len(search_entries(log, "Clock")))
print(len(search_entries(log, "idea")))
print(len(search_entries(log, "a")))
print(search_entries(log, "zzz")) | Statement | True or false? |
|---|---|
| search_entries prints the matches itself. | ? |
| run_search uses format_entry to print each match. | ? |
| A search for a single letter can match many entries. | ? |
| search_entries changes the original list. | ? |
Search is done, and it reuses format_entry. Tomorrow you will build the last feature and run the complete tool.