################################################################################
# Determine the length of the widest column
# It is used so that each db column is presented with just enough space 
# Receives a list of dictionaries
# Returns a dictionary containing the colname : max(length) of each column
################################################################################
def max_width(list_of_dict): 

    if not list_of_dict: return                 #if list_of_dict is empty, return

    result = {}                                 #create a dictionary  

    colnames = list_of_dict[0].keys()           #get the column names
 
    for colname in colnames:                    #iterate thru all column names
        max = len(colname)                      #max is the column name
        for row in list_of_dict:
            colvalue = row[colname]             #get the column value
            colvalue = str(colvalue)            #in case colvalue is numeric
            if len(colvalue) > max:             #if the column value is wider 
                max = len(colvalue)             #take it
        result[colname] = max                   #build a dictionary of colnames and max_width                               

    return(result)