Deduplicate customer records by fuzzy key
Python data engineering interview problem. Difficulty: intermediate. Pattern: Deduplication. About 15 minutes. Part of the Pro drill bank.
A CRM export repeats the same customer under slightly different keys. Dedup must collapse those rows using the fuzzy key the prompt defines, not a naive exact match only.
A customer list has the same person more than once, with small differences like capital letters or extra spaces in the name. 2 records are the same person if the lowercase, trimmed name and the zip code are equal. Group records by name (trimmed and lowercase) plus zip. For each group keep only 1 record: the one with the latest updated_at. If two have the same date, the later one in the list wins. Return the kept records in the order their groups first appeared. Write dedupe_customers(rows). For ' Ann ' and 'ann' with the same zip and dates 2026-01-01 and 2026-02-01, the second record is newer, so only that one is returned. The starter file already has the function name and its print lines. Keep them and fill in the body.
Requirements
- Build a key from the trimmed, lowercase name and the zip.
- Keep 1 record per key: the newest updated_at.
- On equal dates keep the later record.
- Return records in the order their keys first appeared.
Constraints
- Each record is a dictionary with name, zip, updated_at and id.
- updated_at is an ISO date text, so it can be compared as text.
Examples
Input: dedupe_customers([{'name': ' Ann ', 'zip': '94110', 'updated_at': '2026-01-01', 'id': 1}, {'name': 'ann', 'zip': '94110', 'updated_at': '2026-02-01', 'id': 2}]) Output: [{'name': 'ann', 'zip': '94110', 'updated_at': '2026-02-01', 'id': 2}] This input follows the stated rules and produces this output.
Topics: lakebench, python, deduplication.
More Python interview questions · All interview problems · Learn data engineering
Deduplicate customer records by fuzzy key
Interview-style drill: Given customer records with a normalized name+zip key, keep only the most recently updated record per key.
Deduplicate customer records by the fuzzy key described in the prompt.