input: Write a function to optimize an equation by combining like terms. The function should take a string representing the equation as input and return a string with the optimized equation. If the input equation is empty, return an empty string.
  def optimize_equation(equation):
      if not equation:
          return ""
      
      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]
  assert optimize_equation('x + x + y + y + y')=='x^2 + y^3'
  assert optimize_equation('a + a + b + b + b + c + c + c + c')=='a^2 + b^3 + c^4'
  assert optimize_equation('')==''
  assert optimize_equation('d + d + d + d + d')=='d^5'
  assert optimize_equation('e + e + e')=='e^3'
output: def optimize_equation(equation):
      if not equation:
          return ""
      
      term_counts = {}
      for term in equation.split('+'):
          var, count = term.strip().split(' ')
          count = int(count)
          if var in term_counts:
              term_counts[var] += count
          else:
              term_counts[var] = count
  
      new_equation = ""
      for var, count in term_counts.items():
          new_equation += (var + '^' + str(count)) + ' + '
      return new_equation[:-3]