def _onegroup(it, n):
    """Return the next size-n group from the given iterable."""
    toret = []
    for _ in range(n):
        try:
            toret.append(next(it))
        except StopIteration:
            break
    if toret:
        return toret
    else:
        raise StopIteration