Format columns


In this example we use a list of lists that we have not learned yet, but don't worry about that for now. Focus on the output of the two print statements.


examples/format/format_columns.py
data = [
    ["Foo Bar", 42],
    ["Bjorg", 12345],
    ["Roza", 7],
    ["Long Name Joe", 3],
    ["Joe", 12345677889],
]

for entry in data:
    print("{} {}".format(entry[0], entry[1]))

print('-' * 16)

for entry in data:
    print("{:<8}|{:>7}".format(entry[0], entry[1]))

Foo Bar 42
Bjorg 12345
Roza 7
Long Name Joe 3
Joe 12345677889
----------------
Foo Bar |     42
Bjorg   |  12345
Roza    |      7
Long Name Joe|      3
Joe     |12345677889