I have a generator similar to the itertools recipe pairwisethat gives (s0,s1), (s1,s2), (s2, s3).... I want to create another generator from it, which will give the original sequence s0, s1, s2, s3,....
from itertools import *
def pairwise(iterable):
a, b = tee(iterable)
next(b, None)
return izip(a, b)
a = [1,2,3,4]
for item in unpair(pairwise(a)):
print item
How to write unpairas a generator without resorting to lists?
georg source
share