3 ms·
The pairwise recipe function in itertools demonstrates just that (using tee instead of multiplying the iterator): http://docs.python.org/2/library/itertools.ht
by sivanmz 13y ago
The pairwise recipe function in itertools demonstrates just that (using tee instead of multiplying the iterator):
http://docs.python.org/2/library/itertools.html http://docs.python.org/2/library/itertools.html
def pairwise(iterable):
"s -> (s0,s1), (s1,s2), (s2, s3), ..."
a, b = tee(iterable)
next(b, None)
return izip(a, b)