Jan-07-2017, 04:28 PM
Here's my attempt to recreate my code just after waking up:
states = [['Arkansas', 'Little_Rock'], ['Delaware', 'Dover'], ['Illinois', 'Springfield'], ['Indiana', 'Indianapolis'], ['Kentucky', 'Frankfort'], ['New_Jersey', 'Trenton'], ['New_York', 'Albany'], ['North_Carolina', 'Raleigh'], ['Ohilo', 'Columbus'], ['Pennsylvania', 'Harrisburg'], ['South_Carolina', 'Columbia'], ['Texas', 'Austin'], ['Virginia', 'Richmond'], ['West_Virginia', 'Charleston']] max_widths = [] for column_index in range(len(states[0])): column = [row[column_index] for row in states] max_widths.append(len(max([str(datum) for datum in column], key = len))) specs = ['{{:<{}}}'.format(width) for width in max_widths] format_spec = ' '.join(specs) lines = [format_spec.format(*row) for row in states] print('\n'.join(lines))Here's the output:
Output:Arkansas Little_Rock
Delaware Dover
Illinois Springfield
Indiana Indianapolis
Kentucky Frankfort
New_Jersey Trenton
New_York Albany
North_Carolina Raleigh
Ohilo Columbus
Pennsylvania Harrisburg
South_Carolina Columbia
Texas Austin
Virginia Richmond
West_Virginia Charleston
You would just need to vary the justification indicator in the format specification based on the type of the column.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures