input: Write a function to optimize an equation by combining like terms in the form of "variable^count". The function should take a string equation as input, where each term is separated by a '+'. It should return the optimized equation. 
  
  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]
  
  assert optimize_equation('x + x + y + y + y')=='x^2 + y^3'
  assert optimize_equation('a + b + b + b + c')=='a^1 + b^3 + c^1'
  assert optimize_equation('p + p + p')=='p^3'
  assert optimize_equation('q + q + r + r + r + r')=='q^2 + r^4'
  assert optimize_equation('x')=='x^1'
output: def optimize_equation(equation):
      from collections import defaultdict
      terms = defaultdict(int)
      for term in equation.split('+'):
          var, count = term.strip().split(' ')
          terms[var] += int(count)
      
      new_equation = ' + '.join(f'{var}^{count}' for var, count in terms.items())
      return new_equation