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

9. Wildlife Survey Data Lab · Track Unique Visits

Use a set to remove duplicates and a tuple to keep a fixed pair together.

Lesson files · lessons/search-sort-summarise/sets-and-tuples

Before you start
- Keep related records together in a list.
- Count items with len() and join strings for display.

By the end
- Print each habitat once in alphabetical order.
- Use the example counts to explain which duplicate pairs would be lost in a set.

Where you can use it
Use a set of habitat and species pairs to count how many different kinds of sightings a group recorded.

A tuple can group two related values such as an area and a species. A set keeps unique values and can test membership quickly. Use a list when visit order or duplicates carry meaning. Sort a set before printing it in a repeatable report.

Predict
Which collection keeps both identical river visits?
- The original list.
- The set.

Worked example (example.py)

visits = [("river", "heron"), ("river", "heron"), ("ridge", "eagle")]
print(len(visits))
print(len(set(visits)))


Example result
3
2

Print the unique habitats in sorted order from ["river", "ridge", "river"]. Join them using comma-space.

Starter program (starter.py)

visits = [("river", "heron"), ("river", "heron"), ("ridge", "eagle")]
print(len(visits))
print(len(set(visits)))


Hint
Make a set first, then pass it to sorted before joining its values.

Case 1. Try the sample
Input
(No input.)
Expected output
ridge, river

Stretch
Devise a fixture where two species in the same habitat must remain distinct.

Reflect
Which detail would you lose if you changed the visits list to a set too early?

Check your prediction
The original list. The set keeps one unique copy of each pair.
