def splitit(l, n):
    """Utility function to evenly split a list. Handles edge cases.
    There is probably a 1-liner list comprehension to do this, but it would be super gnarly.
    @param l list to split (not a generator)
    @param n number of chunks to split the list into
    @return list of n lists
    """
    # if list is shorter then n, split into a list of lists, each with one entry
    if len(l) < n:
        n = len(l)
    s = len(l) // (n)  # each chunk will either be of size s or size s+1
    m = len(l) % (
        s * n
    )  # remainder after n chunks of size s = how many chunks of size s+1 are needed
    r = []  # result
    p = 0  # pointer
    for i in range(n):
        if i < m:
            r.append(l[p : p + s + 1])
            p += s + 1
        else:
            r.append(l[p : p + s])
            p += s
    return r