Learn the concept
A dictionary maps unique hashable keys to values. It is useful for looking up records by identity. A set stores unique hashable values and supports membership and set operations. Neither should replace a list when duplicate occurrences are meaningful.
Indexing a missing dictionary key raises KeyError; get can return a default. Decide whether a missing field is optional or an error rather than always replacing it with an empty string. Keys must be hashable, so mutable lists cannot serve as dictionary keys.
Use sets to deduplicate identifiers, but retain provenance when you need to explain duplicates. A set alone loses how often an item appeared. For counts, use a dictionary or a counting utility. Distinguish a record ID from its display name: names are often not unique.
Run and inspect
records = {"d1": {"title": "Setup"}, "d2": {"title": "Setup"}}
assert records["d1"]["title"] == "Setup"
assert records.get("missing") is None
seen = set(["d1", "d1", "d2"])
assert len(seen) == 2
assert {"d1", "d3"} - seen == {"d3"}
Your exercise
Build an ID-to-record lookup and separately report duplicate IDs in an input list. Do not deduplicate based on document title.
Check your understanding
Two records with the same title but different IDs remain distinct, while repeated IDs are reported explicitly.