Ask Your Question

Fixed Column Width

asked 2012-10-24 09:03:00 -0500

SLOtoSF gravatar image

updated 2012-10-25 16:41:21 -0500

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 13:41:50 -0500

Jason Grout gravatar image

updated 2012-10-25 16:42:28 -0500

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 10:41:48 -0500

achrzesz gravatar image

updated 2012-10-26 05:13:05 -0500

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 13:20:27 -0500 )edit

look up the python formatting options for strings:

benjaminfjones gravatar imagebenjaminfjones ( 2012-10-25 19:06:58 -0500 )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 09:03:00 -0500

Seen: 103 times

Last updated: Oct 26 '12