First time here? Check out the FAQ!

Ask Your Question
0

Fixed Column Width

asked 12 years ago

SLOtoSF gravatar image

updated 12 years ago

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
Preview: (hide)

2 Answers

Sort by » oldest newest most voted
3

answered 12 years ago

Jason Grout gravatar image

updated 12 years ago

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']])
Preview: (hide)
link
0

answered 12 years ago

achrzesz gravatar image

updated 12 years ago

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

Preview: (hide)
link

Comments

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

SLOtoSF gravatar imageSLOtoSF ( 12 years ago )

look up the python formatting options for strings: http://docs.python.org/library/string.html

benjaminfjones gravatar imagebenjaminfjones ( 12 years ago )

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: 12 years ago

Seen: 379 times

Last updated: Oct 26 '12