def sliding_window(n, seq):
 it = iter(seq)
 d = collections.deque(itertools.islice(it, n), n)
 if (len(d) != n):
  raise StopIteration()
 d_append = d.append
 for item in it:
  (yield tuple(d))
  d_append(item)
 (yield tuple(d))

def sliding_window ( n , seq ) : it = iter ( seq ) d = collections . deque ( itertools . islice ( it , n ) , n ) if ( len ( d ) != n ) : raise StopIteration ( ) d_append = d . append for item in it : ( yield tuple ( d ) ) d_append ( item ) ( yield tuple ( d ) )
a sequence of overlapping subsequences .