title: Python: Read tree like data from text file and store in dictionary
body: <p>I have a text file containing tree like data separated by a space with following structure:
  'Number of branches' 'Name of node' ... 0 (0 means no further branch)
  For example:</p>
  
  <pre><code>1 A 3 B 2 C 0 
          D 0
      E 1 F 0
      G 2 H 0
        I 0
  </code></pre>
  
  <p>the corresponding dictionary 'tree' should be like:</p>
  
  <pre><code>tree = {'A': {'B': {'C': {},
                      'D': {}},
                'E': {'F': {}},
                'G': {'H': {},
                      'I': {}}}}
  </code></pre>
  
  <p>I think recursive way is the right way to do it but I am unable to make it work. I have following function so far:</p>
  
  <pre><code>def constructNodes(branch):
  
      global nodes_temp
  
      if not branch:
          branch = deque(file.readline().strip().split())
      node1 = branch.popleft()
      nodes_temp.add(node1)
      nbBranches = int(branch.popleft())
      for i in xrange(nbBranches):
          constructNodes(branch)
      return nodes_temp
  </code></pre>
  
  <p>Thanks in advance for the help.</p>