input: Write a function to optimize an equation by converting repeated terms into exponential form. The function should take a string representing the equation as input and return the optimized equation as a string.
  
  def optimize_equation(equation):
      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]
  
  equation = 'x + x + y + y + y'
  
  assert optimize_equation(equation)=='x^2 + y^3'
  assert optimize_equation('a + a + b + b + c')=='a^2 + b^2 + c'
  assert optimize_equation('x + y + y + z')=='x + y^2 + z'
  assert optimize_equation('a + b + b + b')=='a + b^3'
  assert optimize_equation('e + e + f + g')=='e^2 + f + g'
output: def optimize_equation(equation):
      variables = {}
      for term in equation.split('+'):
          var, count = term.strip().split(' ')
          count = int(count)
          if var in variables:
              variables[var] += count
          else:
              variables[var] = count
  
      new_equation = ""
      for var, count in variables.items():
          if count > 1:
              new_equation += (var + '^' + str(count)) + ' + '
          else:
              new_equation += var + ' + '
      return new_equation[:-3]