I am new to python and was going through a problem. I have a text file which I read into a list and then divide it into chunks or "teams". The number of sub lists are created based on the number of teams I want. All this is done. But I want to print it out in a nice tabular format. Ive looked into the following questions this, this and this, but they are not what I ma looking for. Ive even looked at pypi modules PrettyTable and DataGrid.
My final list looks like this:
['name9', 'name2'], ['name4', 'name11'], ['name10', 'name3'], ['name7', 'name6'], ['name5', 'name8'], ['name']]
I print it out like this:
for i in range(len(l)):
print "Teams{}\t\t ".format(i+1),
print
for x in itertools.izip_longest(*l, fillvalue="."):
print "\n"
t = "\t\t ".join(str(i) for i in x)
print t
Which results in:
Teams1 Teams2 Teams3 Teams4 Teams5 Teams6
name9 name4 name10 name7 name5 name
name2 name11 name3 name6 name8 .
Is there any way I can get an output like this:
Team 1 Team 2 Team 3 Team 4 Team 5 Team 6
-------------------------------------------------------------------
name9 name4 name10 name7 name5 name
name2 name11 name3 name6 name8 .
And just align them properly?