def print_cols(words, print_func, termwidth=79):
    """Takes a single column of words, and prints it as multiple columns that
    will fit in termwidth columns.
    """
    width = max([word_len(word) for word in words])
    nwords = len(words)
    ncols = max(1, (termwidth + 1) // (width + 1))
    nrows = (nwords + ncols - 1) // ncols
    for row in range(nrows):
        for i in range(row, nwords, nrows):
            word = words[i]
            if word[0] == '\x1b':
                print_func('%-*s' % (width + 11, words[i]),
                           end='\n' if i + nrows >= nwords else ' ')
            else:
                print_func('%-*s' % (width, words[i]),
                           end='\n' if i + nrows >= nwords else ' ')
def print_cols ( words , print_func , termwidth = 79 ) : width = max ( [ word_len ( word ) for word in words ] ) nwords = len ( words ) ncols = max ( 1 , ( termwidth + 1 ) // ( width + 1 ) ) nrows = ( nwords + ncols - 1 ) // ncols for row in range ( nrows ) : for i in range ( row , nwords , nrows ) : word = words [ i ] if word [ 0 ] == '\x1b' : print_func ( '%-*s' % ( width + 11 , words [ i ] ) , end = '\n' if i + nrows >= nwords else ' ' ) else : print_func ( '%-*s' % ( width , words [ i ] ) , end = '\n' if i + nrows >= nwords else ' ' )
Takes a single column of words, and prints it as multiple columns that
    will fit in termwidth columns.