input: def optimize_equation(equation: str) -> str:
      """Given an equation in the form of 'x^n + x^m + y^o ...', optimize it by reducing
      the repeated terms.
      
      >>> optimize_equation('x + x + y + y + y')
      'x^2 + y^3'
      >>> optimize_equation('a + a + a + a + b + b')
      'a^4 + b^2'
      """
      variables = []
      for term in equation.split('+'):
          var, count = term.strip().split(' ')
          variables.append((var, int(count)))
  
      new_equation = ""
      for var, count in variables:
          new_equation += (var + '^' + str(count)) + ' + '
      return new_equation[:-3]
output:     variables = {}
      for term in equation.split('+'):
          var = term.strip()
          if var in variables:
              variables[var] += 1
          else:
              variables[var] = 1
  
      new_equation = ""
      for var, count in variables.items():
          new_equation += (var + '^' + str(count)) + ' + '
      return new_equation[:-3]