Deviopath › Python

Inventory Reconciliation

Hard · Data Processing

Syncing data between two systems usually starts with a diff. You get two snapshots of an inventory, old and new. Each is a list of dicts with a unique string "id" and some other fields.

Write reconcile(old, new) that returns a dict with:

- "added": ids only in new

- "removed": ids only in old

- "changed": for every id in both whose other fields differ, {"id": id, "changes": {field: [old_value, new_value]}}. Only list fields that differ. A field missing on one side counts as None.

Sort added and removed with normal string order, and changed by id. Records without changes are not listed. Index both lists by id in dicts first, so the diff stays fast for big inventories.

Next: Reusable Pages Iterable