Deep Diff of Nested Data

medium
Unit 17 · Data Structures & Recursion0/3 to milestone

Compare two nested structures (dicts, lists and plain values) and report what changed, like a JSON diff in a config review tool.

Implement deep_diff(a, b) returning a list of changes in traversal order:

  • ("added", path, value), ("removed", path, value) and ("changed", path, old, new)
  • Paths: dict keys are joined with . ("db.port"), and list indices use brackets ("servers[2]", "a.b[0].c"). The root path is "".
  • Dicts: visit keys in sorted order (as strings) across both sides. Lists: compare index by index, then report extra items as added or removed.
  • When the types differ (including dict vs list), or two plain values aren't equal, report "changed" at that path rather than recursing.

Also implement diff_summary(changes): a dict counting each kind, with all three keys present.

#recursion#dicts#testing2 visible + 1 hidden tests
solution.py · Python 3.13
Loading editor…
Run your code to see results. ⌘↵ to run · ⌘⇧↵ to submit
Deep Diff of Nested Data · TechGradify