title: Detect changes to a nested dictionary with Python
body: <p>I've seen a few similar questions on SO regarding detecting changes to a dictionary and calling a function when the dictionary changes, such as:</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/6190468/how-to-trigger-function-on-value-change">How to trigger function on value change?</a></li>
  <li><a href="https://stackoverflow.com/questions/26189090/python-detect-if-any-element-in-a-dictionary-changes">python detect if any element in a dictionary changes</a></li>
  </ul>
  
  <p>These examples use variations of the Observer pattern or overloading <code>__setitem__</code>, but all these examples don't detect changes on nested dictionary values.</p>
  
  <p>For example, if I have:</p>
  
  <pre><code>my_dict = {'a': {'b': 1}}
  my_dict['a']['b'] = 2
  </code></pre>
  
  <p>The assignment of <code>2</code> to the element <code>['a']['b']</code> will not be detected.</p>
  
  <p>I'm wondering if there is an elegant way of detecting changes not only to the base elements of a dictionary but all the child elements of a nested dictionary as well.</p>