def __print_table ( table ) : col_width = [ max ( len ( x ) for x in col ) for col in zip ( * table ) ] print ( "| " + " | " . join ( "{:{}}" . format ( x , col_width [ i ] ) for i , x in enumerate ( table [ 0 ] ) ) + " |" ) print ( "| " + " | " . join ( "{:{}}" . format ( '-' * col_width [ i ] , col_width [ i ] ) for i , x in enumerate ( table [ 0 ] ) ) + " |" ) for line in table [ 1 : ] : print ( "| " + " | " . join ( "{:{}}" . format ( x , col_width [ i ] ) for i , x in enumerate ( line ) ) + " |" )
print list table screen width python
Print a list in tabular format Based on https : // stackoverflow . com / a / 8356620
def __print_table(table):
        """Print a list in tabular format
        Based on https://stackoverflow.com/a/8356620"""

        col_width = [max(len(x) for x in col) for col in zip(*table)]
        print("| " + " | ".join("{:{}}".format(x, col_width[i])
                                for i, x in enumerate(table[0])) + " |")
        print("| " + " | ".join("{:{}}".format('-' * col_width[i], col_width[i])
                                for i, x in enumerate(table[0])) + " |")
        for line in table[1:]:
            print("| " + " | ".join("{:{}}".format(x, col_width[i])
                                    for i, x in enumerate(line)) + " |")