import itertools


def threewise(iterable):
  """like `itertools.pairwise`, but returns triples."""
  a, b, c = itertools.tee(iterable, 3)
  next(b, None)
  next(c, None)
  next(c, None)
  return zip(a, b, c)