title: convert a dictionary recursively in Python
body: <p>Here is a dictionary:</p>
  
  <pre><code>data = {
      'a': {
          'b': {
              'c': {
                  'd': {
                      'e': {
                          'f': 1,
                          'g': 50,
                          'h': [1, 2, 4],
                          'i': 3,
                          'j': [7, 9, 6],
                          'k': [
                              [('x', 'abc')],
                              [('y', 'qwe')],
                              [('z', 'zxc')]
                          ]
                      }
                  }
              }
          }
      }
  }
  </code></pre>
  
  <p>My goal is to find and transform values into dictionaries if possible:</p>
  
  <pre><code>data = {
      'a': {
          'b': {
              'c': {
                  'd': {
                      'e': {
                          'f': 1,
                          'g': 50,
                          'h': [1, 2, 4],
                          'i': 3,
                          'j': [7, 9, 6],
                          'k': [{
                              'x': 'abc'
                          }, {
                              'y': 'qwe'
                          }, {
                              'z': 'zxc'
                          }]
                      }
                  }
              }
          }
      }
  }
  </code></pre>
  
  <p>I think that could be done using recursion and I have even written one, but it doesn't work.</p>
  
  <pre><code>def f(d):
    for key, value in d.iteritems():
      if type(d[key]) is dict:
        f(d)
  
      try:
        d[key] = dict(d[key])
      except:
        if type(d[key]) is list:
          for i in d[key]:
            try:
              d[key][i] = dict(d[key][i])
            except:
              pass
  
    return d
  </code></pre>
  
  <p>The error:</p>
  
  <blockquote>
    <p>RecursionError: maximum recursion depth exceeded while calling a Python object</p>
  </blockquote>
  
  <p>How do I make it work?</p>
  
  <p>If you could provide a solution without recursion I'll be glad to get it as well.</p>