Ask Your Question
0

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
3

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: http://docs.python.org/library/string..., http://docs.python.org/library/stdtyp...

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

html.table([[1,'boy','hi'],['mathematics','is','fun']])
edit flag offensive delete link more
0

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

Comments

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: http://docs.python.org/library/string.html

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

Stats

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

Seen: 287 times

Last updated: Oct 26 '12