def group_iter(iterator, n=2):
    """ Given an iterator, it returns sub-lists made of n items.
    (except the last that can have len < n)

    """

    # Use slices instead of an iterator when we have a flat list
    if isinstance(iterator, list):

        length = len(iterator)
        for i in range(int(math.ceil(old_div(float(length), n)))):
            yield iterator[i * n: (i + 1) * n]

    else:
        accumulator = []
        for item in iterator:
            accumulator.append(item)
            if len(accumulator) == n:
                yield accumulator
                accumulator = []

        # Yield what's left
        if len(accumulator) != 0:
            yield accumulator
Given an iterator, it returns sub-lists made of n items.
    (except the last that can have len < n)