The problem is easy, I want to iterate over each element of the list and the next one in pairs (wrapping the last one with the first).
I\'ve thought about two unpyth
def pairs(lst): i = iter(lst) first = prev = item = i.next() for item in i: yield prev, item prev = item yield item, first
Works on any non-empty sequence, no indexing required.