def _find_optimal(rlist, *, separator_size, displaywidth):
    """Calculate optimal info to columnize a list of strings"""
    for nrow in range(1, len(rlist) + 1):
        chk = list(map(max, _chunks(rlist, nrow)))
        sumlength = sum(chk)
        ncols = len(chk)
        if sumlength + separator_size * (ncols - 1) <= displaywidth:
            break

    return {
        "columns_numbers": ncols,
        "rows_numbers": nrow,
        "columns_width": chk,
    }
Calculate optimal info to columnize a list of strings
angrmanagement/vendor/qtconsole/util.py