I’ve rewritten this so it is easier to understand, splitting out complicated code, and removing unused lines:
def record_disp(info): #define a function that takes the input data, info
a=[list(x) for x in info] #turn the input list into a list of lists
lens=[] # make an empty list to store max lengths
#loop with x values from 0 to length of first list
for x in range(len(a[0])):
# get the longest item
maxlen=0
for y in range(len(a)):
maxlen=max(len(str(a[y][x])), maxlen)
lens.append(maxlen)
#for every item print it out table, formatting with spaces
for x in range(len(a)): #for each row
for y in range(len(a[x])): # for each column index in the row
# the previously calculated column width (lens[y])
# is used to work out the number of spaces needed
spacing_needed = lens[y]-len(str(a[x][y]))
# print one cell, spacing it out and delimiting with |
print(str(a[x][y])+" "*spacing_needed,end=" |")
print() # adds a newline at the end of the row
solved How does this code neatly list information side by side? [closed]