title: how to print a Python dictionary in columns
body: <p>Let's say I have a dictionary like the following:</p>
  
  <pre><code>dictionary1 = {
      "Scientology": {
          "source": "LRH",
          "scilon 1": {
              "name": "John Travolta",
              "OT level": 5,
              "wall of fire": True
          },
          "scilon 2": {
              "name": "Tom Cruise",
              "OT level": 6,
              "wall of fire": True
          }
      }
  }
  </code></pre>
  
  <p>I want to be able to print this and other dictionaries of varying depths in aligned columns like the following:</p>
  
  <pre><code>Scientology:
      source: LRH
      scilon 1:
          name:         John Travolta
          OT level:     5
          wall of fire: True
      scilon 2:
          name          Tom Cruise
          OT level:     6
          wall of fire: True
  </code></pre>
  
  <p>I am aware of the <code>pprint</code> approach. It produces a printout like this:</p>
  
  <pre><code>&gt;&gt;&gt; pprint.pprint(dictionary1)
  {'Scientology': {'scilon 1': {'OT level': 5,
                                'name': 'John Travolta',
                                'wall of fire': True},
                   'scilon 2': {'OT level': 6,
                                'name': 'Tom Cruise',
                                'wall of fire': True},
                   'source': 'LRH'}}
  </code></pre>
  
  <p>This is not what I want, not simply because it includes the chain brackets and quotation marks, but because it does not align the sub-values into columns.</p>
  
  <p>My attempt so far is as follows:</p>
  
  <pre><code>def printDictionary(
      dictionary = None,
      indentation = ''
      ):
      for key, value in dictionary.iteritems():
          if isinstance(value, dict):
              print("{indentation}{key}:".format(
              indentation = indentation,
              key = key
          ))
              printDictionary(
                  dictionary = value,
                  indentation = indentation + '   '
              )
          else:
              print(indentation + "{key}: {value}".format(
                  key = key,
                  value = value
              ))
  </code></pre>
  
  <p>This produces the following:</p>
  
  <pre><code>&gt;&gt;&gt; printDictionary(dictionary1)
  Scientology:
     scilon 2:
        OT level: 6
        name: Tom Cruise
        wall of fire: True
     source: LRH
     scilon 1:
        OT level: 5
        name: John Travolta
        wall of fire: True
  </code></pre>
  
  <p>This is approaching what I want, but I can't figure a good way to get the alignment working. Can you think of a way of keeping track of how to align the values and then applying the appropriate indentation?</p>