Iterating over a window in Python

This weekend, I had a fairly common problem: given a sequence of elements and an element in that sequence, I needed to get the next element; if the element was the last in the sequence, then I needed the first element. My first stab at a solution was pretty straightforward: def item_after(elements, item):     […]