Skip to content

Instantly share code, notes, and snippets.

@laixintao
Created June 23, 2021 07:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save laixintao/1752cc65ace20cf9892383260aac404a to your computer and use it in GitHub Desktop.
Save laixintao/1752cc65ace20cf9892383260aac404a to your computer and use it in GitHub Desktop.
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