[Tutor] Matrix

Alan Gauld alan.gauld at freenet.co.uk
Mon Dec 20 09:24:48 CET 2004


> A list of lists is the most logical construction.
> But -- you don't need to assemble the rows separately --
> this works too:
>  >>> my_matrix_as_lists = [ [4, 6, 8, 1],\
> ...   [2, 5, 1, 3],\
> ...   [2, 1, 2, 8] ]

And you don't need the line continuation characters either. 
Because Python can tell that the brackets don't match you 
can just add the newlines directly:

>>> mx = [ [1,2,3,4],
...        [5,6,7,8] ]
>>>

Alan g


More information about the Tutor mailing list