title: Python: String formatting together with enumerate? (Producing a nice string representation of a polynomial in a pythonic way)
body: <p>I started to write a little class that should represent polynomial functions in one variable. I'm aware that the powerful sympy module is out there but I decided that it is simpler to put a few lines of code instead of loading the entire sympy module. The main reason is that simply just uses a level of abstraction (i.e. dealing with variables and rings) that I don't need.</p>
  <p>So here is what I did:</p>
  <pre><code>class Polynomial:
      &quot;&quot;&quot;Class representing polynomials.&quot;&quot;&quot;
      
      def __init__(self, *coefficients):
          self.coefficients = list(coefficients)
          &quot;&quot;&quot;Coefficients of the polynomial in the order a_0,...a_n.&quot;&quot;&quot;
       
      def __repr__(self):
          return &quot;Polynomial(%r)&quot; % self.coefficients
              
      def __call__(self, x):    
          res = 0
          for index, coeff in enumerate(self.coefficients):
              res += coeff * x** index
          return res
  </code></pre>
  <p>I would like to also implement <code>__str___</code> with the same output as produced by the for loop:</p>
  <pre><code>res = &quot;&quot;
  for index, coeff in enumerate(self.coefficients):
      res += str(coeff) + &quot;x^&quot;+str(index)
  </code></pre>
  <p>First, I expected something like <code>&quot;$r*x^%r&quot; % enumerate(self.coefficients)</code> to work but it doesn't. I tried to convert the <code>enumerate(...)</code> to tuple but this also didn't solve the problem.</p>
  <p>Any ideas for a pythonic, one-line return statement I could use for <code>__str__</code>?</p>