title: how do i map to a dictionary rather than a list?
body: <p>i have the following function, which doe a basic job of mapping an lxml object to a dictionary...</p>
  
  <pre><code>from lxml import etree 
  
  tree = etree.parse('file.xml')
  root = tree.getroot()
  
  def xml_to_dict(el):
      d={}
      if el.text:
          print '***write tag as string'
          d[el.tag] = el.text
      else:
          d[el.tag] = {}
      children = el.getchildren()
      if children:
          d[el.tag] = map(xml_to_dict, children)
      return d
  
      v = xml_to_dict(root)
  </code></pre>
  
  <p>at the moment it gives me....</p>
  
  <pre><code>&gt;&gt;&gt;print v
  {'root': [{'a': '1'}, {'a': [{'b': '2'}, {'b': '2'}]}, {'aa': '1a'}]}
  </code></pre>
  
  <p>but i would like....</p>
  
  <pre><code>&gt;&gt;&gt;print v
  {'root': {'a': ['1', {'b': [2, 2]}], 'aa': '1a'}}
  </code></pre>
  
  <p>how do i rewrite the function xml_to_dict(el) so that i get the required output?</p>
  
  <p>here's the xml i'm parsing, for clarity.</p>
  
  <pre><code>&lt;root&gt;
      &lt;a&gt;1&lt;/a&gt;
      &lt;a&gt;
          &lt;b&gt;2&lt;/b&gt;
          &lt;b&gt;2&lt;/b&gt;
      &lt;/a&gt;
      &lt;aa&gt;1a&lt;/aa&gt;
  &lt;/root&gt;
  </code></pre>
  
  <p>thanks :)</p>