Skip to content

Instantly share code, notes, and snippets.

@drasch
Created February 12, 2021 19:45
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 drasch/53c790d58477b8546b84786872cee5fc to your computer and use it in GitHub Desktop.
Save drasch/53c790d58477b8546b84786872cee5fc to your computer and use it in GitHub Desktop.
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