Created
June 23, 2021 07:07
-
-
Save laixintao/1752cc65ace20cf9892383260aac404a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
number1| x| name | |
4x| 3| Hi | |
2| 1|808890312093 | |
5|Hi| Bye |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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