Ask Your Question

Fixed Column Width

asked 2012-10-24 16:03:00 +0200

SLOtoSF gravatar image

updated 2012-10-25 23:41:21 +0200

Jason Grout gravatar image

Say I have two lists a and b: a = [1,'boy','tree'] and b = ['mathematics','is','fun'].

How can I display this evenly spaced like below? (can someone please edit the below so that there is actually evenly spaced columns, as the editor is deleting the spacing)

1           boy     tree
mathematics is      fun
edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2012-10-24 20:41:50 +0200

Jason Grout gravatar image

updated 2012-10-25 23:42:28 +0200

Relevant Python doc pages are:,

Update: if you're in the notebook, you can also use html.table:

edit flag offensive delete link more

answered 2012-10-24 17:41:48 +0200

achrzesz gravatar image

updated 2012-10-26 12:13:05 +0200

for _ in [a,b]: print '%-15s%-8s%-8s' % (_[0],_[1],_[2])

edit flag offensive delete link more


This isn't helpful for me because it right aligns the third column and creates variable space.

SLOtoSF gravatar imageSLOtoSF ( 2012-10-24 20:20:27 +0200 )edit

look up the python formatting options for strings:

benjaminfjones gravatar imagebenjaminfjones ( 2012-10-26 02:06:58 +0200 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2012-10-24 16:03:00 +0200

Seen: 311 times

Last updated: Oct 26 '12