import six


def grouper(iterable, n, fillvalue=None):
  """Collect data into fixed-length chunks or blocks

  See https://docs.python.org/2/library/itertools.html.

  >>> [''.join(subiter) for subiter in grouper('ABCDEFG', 3, 'x')]
  ['ABC', 'DEF', 'Gxx']

  """
  # grouper('ABCDEFG', 3, 'x') --> ABC DEF Gxx
  args = [iter(iterable)] * n
  return six.moves.zip_longest(fillvalue=fillvalue, *args)