def printTable(myDict, colList=None):
    """ Pretty print a list of dictionaries (myDict) as a dynamically sized table.
   If column names (colList) aren't specified, they will show in random order.
   Author: Thierry Husson - Use it as you want but don't blame me.
   """
if not colList:
    colList = list(list(myDict[0].keys()) if myDict else [])
myList = [colList]
for item in myDict:
    myList.append([str(item[col] or '') for col in colList])
colSize = [max(map(len, col)) for col in zip(*myList)]
formatStr = ' | '.join(['{{:<{}}}'.format(i) for i in colSize])
myList.insert(1, [('-' * i) for i in colSize])
for item in myList:
    pass
Python - Printing a dictionary as a horizontal table with headers