def nwise(iter, n):
iterset = [iter]<EOL>while len(iterset) < n:<EOL><INDENT>iterset[-<NUM_LIT:1>:] = itertools.tee(iterset[-<NUM_LIT:1>])<EOL>next(iterset[-<NUM_LIT:1>], None)<EOL><DEDENT>return six.moves.zip(*iterset)<EOL>
Like pairwise, except returns n-tuples of adjacent items.
s -> (s0,s1,...,sn), (s1,s2,...,s(n+1)), ...