title: Python: changing dictionary recursively
body: <p>I have a question about dictionaries in Python.</p>
  
  <p>I have a dictionary like this:</p>
  
  <pre><code>D = {'key1' : ['key3'], 'key2' : {}, 'key3' : ['key2']}
  </code></pre>
  
  <p>And my objective is that all the values are substituted as far as possible like this:</p>
  
  <pre><code>After first iteration:
  D = {'key1' : {'key3' : ['key2']}, 'key2' : {}, 'key3' : {'key2' : {}]}
  
  After second iteration:
  D = {'key1' : {'key3' : {'key2' : {}}}, 'key2' : {}, 'key3' : ['key2']}
  </code></pre>
  
  <p>Is it possible to do that?</p>
  
  <p>I thought something like this:</p>
  
  <pre><code>for k in D.keys():
      try:
          if D[k] in D.keys:
              D[k] = D[D[k]]
      except:
          pass
  </code></pre>
  
  <p>I know it's not correct and it's not working. I think that maybe I should use a recursive function.
  Could you tell me how can I update the values in the dictionary correctly?</p>
  
  <p>Sorry if my explanation is not clear but I hope you get the idea.</p>
  
  <p>Thanks!</p>