Printing Columns

Lindstrom Greg - glinds Greg.Lindstrom at acxiom.com
Tue Apr 15 13:04:55 EDT 2003


Hello-
I have been working on a little project and have come across an interesting
(to me) problem.  I have a list of stuff that I would like to print to
stdout in columns.  Now, it's no problem to print it out as follows:

myList = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H']

	A	B	C
	D	E	F
	G	H

but I would like

	A	D	G
	B	E	H
	C	F

problem is, the code (all 12 lines) is a bit convoluted and would not be
easy for the next person using it to figure out (and in my mind,
maintainability is priority one; that's why I use Python).  I would like to
know if there is a "pythonic" way to do this. So, here are the specs....

Given a list of length N with 0<=N<=infinity and a number of columns, C (C>0
and may be less than N), how do we print out the elements of the list in the
above (column major?) form?

Thanks for your thoughts....I'll post mine in a day or two.
--greg





**********************************************************************
The information contained in this communication is
confidential, is intended only for the use of the recipient
named above, and may be legally privileged.
If the reader of this message is not the intended
recipient, you are hereby notified that any dissemination, 
distribution, or copying of this communication is strictly
prohibited.
If you have received this communication in error,
please re-send this communication to the sender and
delete the original message or any copy of it from your
computer system. Thank You.






More information about the Python-list mailing list