input: Write a python function to parse an XML string into a nested dictionary.
  assert parse_xml('<root><person><name>John</name><age>27</age><hobbies><hobby>Movies</hobby><hobby>Photography</hobby></hobbies></person></root>') == {'person': {'name': 'John', 'age': '27', 'hobbies': {'hobby': ['Movies', 'Photography']}}}
  assert parse_xml('<root><person><name>Alice</name><age>30</age><hobbies><hobby>Reading</hobby><hobby>Cycling</hobby></hobbies></person></root>') == {'person': {'name': 'Alice', 'age': '30', 'hobbies': {'hobby': ['Reading', 'Cycling']}}}
  assert parse_xml('<root><person><name>Bob</name><age>22</age><hobbies><hobby>Gaming</hobby></hobbies></person></root>') == {'person': {'name': 'Bob', 'age': '22', 'hobbies': {'hobby': ['Gaming']}}}
output: def parse_xml(xml_string):
      import xml.etree.ElementTree as ET
      
      def xml_to_dict(element):
          children = list(element)
          if not children:
              return element.text
          result = {}
          for child in children:
              child_result = xml_to_dict(child)
              if child.tag not in result:
                  result[child.tag] = child_result
              else:
                  if not isinstance(result[child.tag], list):
                      result[child.tag] = [result[child.tag]]
                  result[child.tag].append(child_result)
          return result
      
      root = ET.fromstring(xml_string)
      return xml_to_dict(root)