2 ms·
FYI, the official documentation of itertools has its very own pairwise example: def pairwise(iterable): "s -> (s0,s1), (s1,s2), (s2, s3), ..."
by e12e 12y ago
FYI, the official documentation of itertools has its very own pairwise example:
def pairwise(iterable):
"s -> (s0,s1), (s1,s2), (s2, s3), ..."
a, b = tee(iterable)
next(b, None)
return izip(a, b)
https://docs.python.org/2/library/itertools.html#itertools.izip https://docs.python.org/2/library/itertools.html#itertools.i...
- baq 12y agofor the record: the official itertools docs have a lot more examples than this one and they're all really worth knowing about if not studying.