input: Write a function to optimize an equation by combining like terms. The function should take a string representing the equation where terms are separated by '+' signs, and return a new string with the combined terms. The input equation may have terms in any order and may have any number of terms for each variable. If the input is an empty string, the function should return an empty string.
  
  def optimize_equation(equation):
      if not equation:
          return ""
      variables = {}
      for term in equation.split('+'):
          var = term.strip()
          if var in variables:
              variables[var] += 1
          else:
              variables[var] = 1
  
      new_equation = ""
      for var in variables:
          new_equation += (var + '^' + str(variables[var])) + ' + '
      return new_equation[:-3]
  
  assert optimize_equation('x + x + y + y + y') == 'x^2 + y^3'
  assert optimize_equation('a + b + a + a + b') == 'a^3 + b^2'
  assert optimize_equation('c + c + c') == 'c^3'
  assert optimize_equation('') == ''
  assert optimize_equation('d + e + f') == 'd^1 + e^1 + f^1'
  assert optimize_equation('g + h + h + h + g + g') == 'g^3 + h^3'
output: 
  def optimize_equation(equation):
      if not equation:
          return ""
      variables = {}
      for term in equation.split('+'):
          var = term.strip()
          if var in variables:
              variables[var] += 1
          else:
              variables[var] = 1
  
      new_equation = ""
      for var in variables:
          new_equation += (var + '^' + str(variables[var])) + ' + '
      return new_equation[:-3]
  