Newbiequestion about lists and arrays....

Michael holmboe at kth.se
Sat Sep 6 23:20:00 CEST 2003


Hi pythonians! (or whatever you call yourselfs...)

I would like to use an multidimensional matrix (3D or more) with
numbers (int:s and float:s). Could i use lists or arrays? How can i
retrieve a single element out of a list thats already in an other list
thats already in an other list (and so on...)

An example...

c=[1]*3
for y in range(3):
        for x in range(3):
            
            c[x]=[1,2,3]
        p[y]=c

p[1][1][1]=888
print p[1][1][1]
print p



for this code example, how do i assign 888 to only one element (for
example, the element in the middle) in the matrix and not to the three
elements shown below?

>>> 
888
[[[1, 2, 3], [1, 888, 3], [1, 2, 3]],
 [[1, 2, 3], [1, 888, 3], [1, 2, 3]], 
 [[1, 2, 3], [1, 888, 3], [1, 2, 3]]]
>>> 

Why does:

p[0][1][1]=888

and

p[1][1][1]=888

print out the same result?

Helping bitteplease.

/Michael




More information about the Python-list mailing list