──────────────────────────────────────

12. Wildlife Survey Data Lab · Build a Wildlife Observation Report

Filter fictional records, aggregate counts and report a deterministic ranking.

Lesson files · lessons/search-sort-summarise/wildlife-report

Before you start
- Filter records using a condition.
- Add repeated values to a dictionary total.
- Sort records using a two-part key.

By the end
- Report species totals for a habitat, highest count first with alphabetical ties.
- Check the message for a search with no observations.

Where you can use it
Summarise a site survey for a team leader by gathering repeated sightings and ranking species by their total count.

A reporting workflow is easiest to test in three steps. Select rows for the requested habitat. Add counts by species. Sort the aggregate, then format a report. A missing habitat is a valid search with no results.

Predict
What should two river observations of two and three herons produce?
- heron: 3
- heron: 5

Worked example (example.py)

totals = {}
for name, count in [("heron", 2), ("heron", 3)]:
    totals[name] = totals.get(name, 0) + count
print(totals["heron"])


Example result
5

Use the starter records. Read a habitat, count total animals per species, and print species: total from high count to low. Sort tied names alphabetically. Print No sightings. when nothing matches.

Starter program (starter.py)

records = [("river", "heron", 2), ("river", "ibis", 5), ("river", "heron", 3), ("ridge", "eagle", 2)]
print(f"Reading habitat: {input().strip().lower()}")


Starter input
river

Hint
Use a dictionary for totals, then sort totals.items() with a (-count, name) key.

Case 1. Try the sample
Input
river
Expected output
heron: 5
ibis: 5

Case 2. Another habitat
Input
 Ridge 
Expected output
eagle: 2

Case 3. No observations
Input
forest
Expected output
No sightings.

Project checklist
Run the sample case.

Project checklist
Try one different case and explain what happened.

Marking criterion
Program behaviour (4 points)
Each required behaviour works on the supplied cases.

Marking criterion
Use of the lesson concept (3 points)
The code uses the main idea in a clear, purposeful way.

Marking criterion
Test evidence (2 points)
The reflection describes a case, its expected result and what happened.

Marking criterion
Explanation (1 points)
The learner explains a change or design decision in their own words.

Stretch
Add a total across all habitats and compare it to one filtered report.

Reflect
How could you test the sort independently from the data filtering?

Check your prediction
heron: 5 Add each new count to the current species total.
