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
Of course, you can always use a deque:
from collections import deque from itertools import * def pairs(lst, n=2): itlst = iter(lst) start = list(islice(itlst, 0, n-1)) deq = deque(start, n) for elt in chain(itlst, start): deq.append(elt) yield list(deq)