Created
February 12, 2021 19:45
-
-
Save drasch/53c790d58477b8546b84786872cee5fc 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
columns = [["apples", "oranges", "pears", "eggplant"], | |
["red", "blue", "green"], | |
["joey", "matt", "david", "someone else"]] | |
columns = {"fruit": ["apples", "oranges", "pears", "eggplant"], | |
"colors": ["red", "blue", "green", "purple"], | |
"names": ["joey", "matt", "david", "someone else"]} | |
widths = [ | |
max([len(entry) for entry in column]) | |
for column in columns | |
] | |
for i in range(0, len(columns[0])): | |
entries = [ | |
columns[j][i] if i < len(columns[j]) else "" | |
for j in range(len(columns)) | |
] | |
justified = [] | |
for j in range(len(columns)): | |
justified.append(entries[j].rjust(widths[j])) | |
print(" ".join(justified)) | |
print() | |
print() | |
for entries in zip(*columns): | |
justified = [ | |
entries[j].rjust(widths[j]) | |
for j in range(len(columns)) | |
] | |
print(" ".join(justified)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment