Jun-30-2018, 04:10 PM
Here's a simple example I whipped up:
def table(rows): max_widths = [] for column in zip(*rows): max_widths.append(max([len(text) for text in column])) template = ' '.join(['{{:<{}}}'.format(width) for width in max_widths]) return '\n'.join([template.format(*row) for row in rows]) knights = [['Sir Lancelot', 'The Holy Grail', 'Blue'], ['Sir Robin', 'The Holy Grail', "I don't know that."], ['Sir Galahad', 'The Grail', 'Blue. No, yel...'], ['King Arthur', 'The Holy Grail', 'What do you mean?']] print(table(knights))
Output:Sir Lancelot The Holy Grail Blue
Sir Robin The Holy Grail I don't know that.
Sir Galahad The Grail Blue. No, yel...
King Arthur The Holy Grail What do you mean?
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures