Skip to content

Instantly share code, notes, and snippets.

Created Jun 23, 2021
What would you like to do?
number1| x| name
4x| 3| Hi
2| 1|808890312093
5|Hi| Bye
table = [
['number1', 'x', 'name'],
["4x", "3", "Hi"],
["2", "1", "808890312093"],
["5", "Hi", "Bye"]
column_max_width = [max(len(row[column_index]) for row in table) for column_index in range(len(table[0]))]
row_format = ["{:>"+str(width)+"}" for width in column_max_width]
for row in table:
print("|".join([print_format.format(value) for print_format, value in zip(row_format, row)]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment