Pythonic way of determining if the current element is the first or last element of a generator?
<p>I am going through a generator, whats the Pythonic way of determining if the current element is the first or last element of a generator, given that they need special care?</p>

<p>thanks</p>

<p>basically generating tags, so i have items like</p>

<pre><code>&lt;div class="first"&gt;1&lt;/div&gt;
&lt;div&gt;...&lt;/div&gt;
&lt;div class="last"&gt;n&lt;/div&gt;
</code></pre>

<p>so i would like to keep the last item in loop?</p>
