def break_into_chunks(doc, max_words=250):
    """
    Breaks a list into lists of lists of length max_words
    Also works on lists:

    >>> doc = ["a", "b", "c", "d", "e"]
    >>> break_into_chunks(doc, max_words=2)
        [['a', 'b'], ['c', 'd'], ['e']]
    """
    out = []
    chunk = []
    for i, token in enumerate(doc, 1):
        chunk.append(token)
        if (i > 0 and i % max_words == 0) or i == len(doc):
            out.append(chunk)
            chunk = []
    return out