def format_integer(number, group_size=3):
  """Formats integers into groups of digits."""
  assert group_size > 0

  number = str(number)
  parts = []

  while number:
    number, part = number[:-group_size], number[-group_size:]
    parts.append(part)

  number = ' '.join(reversed(parts))
  return number