code: def dictify(r, root=True):
      
      if root:
          return {r.tag: dictify(r, False)}
      d = {}
      if r.text and r.text.strip():
          try:
              return int(r.text)
          except ValueError:
              try:
                  return float(r.text)
              except ValueError:
                  return r.text
      for x in r.findall("./*"):
          if x.tag in d and not isinstance(d[x.tag], list):
              d[x.tag] = [d[x.tag]]
              d[x.tag].append(dictify(x, False))
          else:
              d[x.tag] = dictify(x, False)
      return d
docs: Convert an ElementTree into a dict.