def chunks(a, n):
    """ Splits a range into roughly equal sized chunks.
    """
    a_list = list(a)
    k, m = divmod(len(a_list), n)
    return [a_list[i * k + min(i, m):(i + 1) * k + min(i + 1, m)] 
        for i in list(range(n))]