def group(n, lst, discard_underfull = False):
    """Split sequence into subsequences of given size.  Optionally discard or
    include last subsequence if it is underfull
    """
    out = []
    for i in range(0, len(lst), n):
        out.append(lst[i:i+n])
    if discard_underfull and len(out[-1]) < n:
        out.pop()
    return out