title: Python dictionary formatting
body: <p>I made a Python function to convert dictionaries to formatted strings. My goal was to have a function take a dictionary for input and turn it into a string that looked good. For example, something like <code>{'text':'Hello', 'blah':{'hi':'hello','hello':'hi'}}</code> would be turned into this:</p>
  
  <pre>
  text:
      Hello
  blah:
      hi:
          hello
      hello:
          hi
  </pre>
  
  <p>This is the code I wrote:</p>
  
  <pre><code>indent = 0
  
  def format_dict(d):
      global indent
      res = ""
      for key in d:
          res += ("   " * indent) + key + ":\n"
          if not type(d[key]) == type({}):
              res += ("   " * (indent + 1)) + d[key] + "\n"
          else:
              indent += 1
              res += format_dict(d[key])
              indent -= 1
      return res
  #test
  print format_dict({'key with text content':'some text', 
                    'key with dict content':
                    {'cheese': 'text', 'item':{'Blah': 'Hello'}}})
  </code></pre>
  
  <p>It works like a charm. It checks if the dictionary's item is another dictionary, in which case it process that, or something else, then it would use that as the value. The problem is: I can't have a dictionary and a string together in a dictionary item. For example, if I wanted:</p>
  
  <pre>
  blah:
      hi
      hello:
          hello again
  </pre>
  
  <p>there'd be no way to do it. Is there some way I could have something like a list item in a dictionary. Something like this <code>{'blah':{'hi', 'hello':'hello again'}}</code>? And if you provide a solution could you tell me how I would need to change my code (if it did require changes).<br/>
  <strong>Note</strong>: I am using python 2.5</p>