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?
thanks
basically generating tags, so i have items like
<div class="first">1</div>
<div>...</div>
<div class="last">n</div>
so i would like to keep the last item in loop?
Here’s an enumerate-like generator that skips ahead one; it returns -1 for the last element.
It can’t tell whether the generator passed to it is “fresh” or not, but it still tells you when the end is nigh:
Once an iterator is used up, it raises
StopIterationas usual.