How To Print Values From Lists In Tabular Format (python)?
Using python 2.7, I want to display the values in tabular format, without using pandas/prettytable. I am a beginner to python and am trying to learn. Below is the values I have in
Solution 1:
You're pretty close!
defprint_results_table(data, listA):
str_l = max(len(t) for t in listA)
str_l += 2# add two spaces between elements# print the titlesfor title in listA:
print('{:<{length}s}'.format(title, length = str_l), end='')
print()
# print the valuesfor row in data:
for val in row:
print('{:<{length}s}'.format(val, length = str_l), end='')
print()
Output:
Alpha Beta gama cat
AB C D
E F G H
I J K L
M N O P
Post a Comment for "How To Print Values From Lists In Tabular Format (python)?"