Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def record_disp(info):
- a=[list(x) for x in info]
- table=[]
- lens=[]
- for x in range(len(a[0])):
- maxlen=0
- for y in range(len(a)):
- maxlen=len(str(a[y][x])) if len(str(a[y][x]))>maxlen else maxlen
- lens.append(maxlen)
- for x in range(len(a)):
- for y in range(len(a[x])):
- print(str(a[x][y])+(" "*(lens[y]-len(str(a[x][y])))),end=" |")
- print()
- 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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement