SZanlongo
3/17/2016 - 7:02 PM

Iterate through pairs of items in a Python list From https://stackoverflow.com/questions/5764782/iterate-through-pairs-of-items-in-a-python

from itertools import tee, izip
def pairwise(iterable):
    "s -> (s0,s1), (s1,s2), (s2, s3), ..."
    a, b = tee(iterable)
    next(b, None)
    return izip(a, b)

for v, w in pairwise(a):
    ...