input: 
  def optimize_equation(equation: str) -> str:
      """Optimize given equation by transforming repeated addends into power expressions.
      >>> optimize_equation('x + x + y + y + y')
      'x^2 + y^3'
      >>> optimize_equation('a + a + b + b + b + b')
      'a^2 + b^4'
      """
      from collections import Counter
      variables = Counter()
      for term in equation.split('+'):
          var, count = term.strip().split(' ')
          variables[var] += int(count)
  
      new_equation = ""
      for var, count in variables.items():
          new_equation += (var + '^' + str(count)) + ' + '
      return new_equation[:-3]
  
output:     from collections import Counter
      variables = Counter()
      for term in equation.split('+'):
          var = term.strip()
          variables[var] += 1
  
      new_equation = ""
      for var, count in variables.items():
          new_equation += (var + '^' + str(count)) + ' + '
      return new_equation[:-3]