title: How to track state when iterating in Python's Mako Templates
body: <p>I want to loop over a list and print the elements seperated by ',', with no trailing comma. I can't just <code>', '.join(headings)</code> because of the formating and escaping. But the following obviously leaves me with a trailing comma.</p>
  
  <pre><code>% for x in headings:
    &lt;a href='#${x|u}'&gt;${x}&lt;/a&gt;, \
  % endfor
  </code></pre>
  
  <p>Or more generally: When iterating over something in a Mako template, is there a way to know  if I reached the last element (or first, or nt)?</p>