PY-58

Compare Manifests Field by Field

  • Medium
  • Records and Evidence
  • Python

Task

Write compare_manifests(left, right). Each manifest is made from dictionaries, lists, and scalar values. Compare the complete nested structures and return:

{"added": {}, "removed": {}, "changed": {}}

Each evidence dictionary uses a path tuple as its key. A dictionary step is ("key", key) and a list step is ("index", index). The root path is ().

  • A dictionary key present only on the right is added; store its right value.
  • A dictionary key present only on the left is removed; store its left value.
  • Extra right list positions are added; extra left positions are removed.
  • Unequal scalar values are changed; store (left_value, right_value).
  • When the values at one path have different types, record that path once as changed and do not descend into either value.

Visit shared dictionary keys in left insertion order, then right-only keys in right insertion order. Visit list positions from left to right. Do not report a parent container merely because one of its children differs.

Example

The changed path is (("key", "model"), ("key", "width")). The added path is (("key", "tags"), ("index", 1)).

Your implementation

Edit solution.py and keep this function signature:

Do not modify either manifest, stringify paths, print, or ask for input.