input: from typing import List
  
  
  def optimize_equation(equation: str) -> str:
      """ Given a string representation of a sum of terms like 'x + x + y + y + y',
      optimize it to a form like 'x^2 + y^3'. The input format is 'var + var' and the 
      output should be 'var^count + var^count'.
      >>> optimize_equation('x + x + y + y + y')
      'x^2 + y^3'
      
      >>> optimize_equation('a + a + a + b + b + c')
      'a^3 + b^2 + c^1'
      """
      variables = []
      for term in equation.split('+'):
          var = term.strip()
          variables.append(var)
  
      new_equation = ""
      from collections import Counter
      count_dict = Counter(variables)
      for var, count in count_dict.items():
          new_equation += (var + '^' + str(count)) + ' + '
      
      return new_equation[:-3]
output:     variables = []
      for term in equation.split('+'):
          var = term.strip()
          variables.append(var)
  
      new_equation = ""
      from collections import Counter
      count_dict = Counter(variables)
      for var, count in count_dict.items():
          new_equation += (var + '^' + str(count)) + ' + '
      
      return new_equation[:-3]