The answer to your question depends on your learning objectives. If you are trying to get matrices before "click" to use them later, I would suggest looking at the Numpy array instead of a list of lists. This will allow you to easily cut rows and columns and subsets. Just try to get a column from the list of lists and you will be disappointed.
Using the list of lists as a matrix ...
Let's take your list of lists, for example:
L = [list("ABCDE") for i in range(5)]
It is easy to get subelements for any row:
>>> L[1][0:3] ['A', 'B', 'C']
Or a whole line:
>>> L[1][:] ['A', 'B', 'C', 'D', 'E']
But try flipping this around to get the same elements in a column format, and that won't work ...
>>> L[0:3][1] ['A', 'B', 'C', 'D', 'E'] >>> L[:][1] ['A', 'B', 'C', 'D', 'E']
You will need to use something like list comprehension to get all the 1st elements ....
>>> [x[1] for x in L] ['B', 'B', 'B', 'B', 'B']
Enter matrices
If you use an array instead, you get the slicing and indexing that you would expect from MATLAB or R (or most other languages, for that matter):
>>> import numpy as np >>> Y = np.array(list("ABCDE"*5)).reshape(5,5) >>> print Y [['A' 'B' 'C' 'D' 'E'] ['A' 'B' 'C' 'D' 'E'] ['A' 'B' 'C' 'D' 'E'] ['A' 'B' 'C' 'D' 'E'] ['A' 'B' 'C' 'D' 'E']] >>> print Y.transpose() [['A' 'A' 'A' 'A' 'A'] ['B' 'B' 'B' 'B' 'B'] ['C' 'C' 'C' 'C' 'C'] ['D' 'D' 'D' 'D' 'D'] ['E' 'E' 'E' 'E' 'E']]
Grab line 1 (as in the lists):
>>> Y[1,:] array(['A', 'B', 'C', 'D', 'E'], dtype='|S1')
Take column 1 (new!):
>>> Y[:,1] array(['B', 'B', 'B', 'B', 'B'], dtype='|S1')
So now to create a printed matrix:
for mycol in Y.transpose(): print " ".join(mycol) AAAAA BBBBB CCCCC DDDDD EEEEE